问题描述
我在我的 SalesForce DE 站点中创建了一个简单的自定义联系人对象(API 名称为 Contact__c),该对象具有一个 Full_Name__c 字段(用于测试连接).
I have a simple custom contact object (with API name Contact__c) that I've created in my SalesForce DE site that has a single field (for testing connectivity) of Full_Name__c.
然后我试图通过 PHP 检索所有联系人,特别是该字段:
I am then trying to retrieve all of the contacts, specifically this field via PHP:
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(API_PATH . '/soapclient/partner.wsdl');
$mylogin = $mySforceConnection->login(API_USER, API_PASS . API_SECURITY_TOKEN);
$query = 'SELECT C.Id, C.Full_Name__c
FROM Contact__c C';
$result = $mySforceConnection->query($query);
$sObject = new SObject($result->records[0]);
print_r($sObject);
} catch(Exception $e) {
print_r($e);
}
我已经下载了最新的partner.wdsl(虽然作为合作伙伴WSDL,它是松散类型的,不需要在创建/添加自定义对象和/或更新字段时下载,对吗?).我已经验证用户可以通过 ForceExplorer 连接并查看自定义字段.但是当我运行上面的代码时,它连接但只返回以下内容:
I've downloaded the latest partner.wdsl (although as a partner WSDL, it is loosely typed and does not need to be downloaded with the creation/addition of custom objects and/or updated fields, correct?). I've verified that the user can connect and see the custom fields via the ForceExplorer. But when I run the above code, it connects but returns just the following:
SObject Object ( [type] => Contact__c [fields] => [Id] => a )
我没有收到任何错误、无效字段错误等,但我一生都无法弄清楚为什么这不起作用.
I am not getting any errors, invalid field error, etc, but for the life of me can't figure out why this isn't working.
我在这里看到了这个示例,但它似乎特定于 Enterprise vs Partner,并且每次更改自定义字段时都需要下载最新的 Enterprise.wsdl.
I saw this example here, but it seems to be specific to Enterprise vs Partner, and the need to download the latest enterprise.wsdl every-time you change custom fields.
有什么指点吗?
推荐答案
我相信已经弄清楚了,问题与我如何解析返回的数据有关.我现在没有将返回的数据输入到 SObject 中,而是直接访问它:
Figured it out I believe, the problem related to how I was parsing the data that was being returned. Instead of feeding the returned data into an SObject, I am now just accessing it directly:
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(API_PATH . '/soapclient/partner.wsdl');
$mylogin = $mySforceConnection->login(API_USER, API_PASS . API_SECURITY_TOKEN);
$query = 'SELECT C.Id, C.Full_Name__c
FROM Contact__c C';
$result = $mySforceConnection->query($query);
for($i = 0; $i < count($result->records); $i++) {
print_r($result->records[$i]->fields->Full_Name__c);
}
} catch(Exception $e) {
print_r($e);
}
这篇关于SalesForce.com:通过 PHP 检索自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!