Salesforce php工具包更新自定义字段

时间:2015-02-17 08:57:15

标签: php salesforce

我必须创建从我的webapp到salesforce的记录:

error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
ini_set('xmlrpc_errors', true);

define("USERNAME", "xxxxxxxxx");
define("PASSWORD", "xxxxxxxxx");
define("SECURITY_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxx");

require_once ('soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

function createRecord(){

    global $mySforceConnection;

    $records = array();

    $records[0] = new stdclass();
    $records[0]->FirstName = 'Myriam';
    $records[0]->LastName = 'Makeba';
    $records[0]->Phone = '(510) 555-5555';
    $records[0]->BirthDate = '1957-01-25';
    $records[0]->contractType__c = "CDI";

    $response = $mySforceConnection->create($records, 'Contact');

    $ids = array();
    foreach ($response as $i => $result) {
        echo $records[$i]->FirstName . " " . $records[$i]->LastName . " "
                . $records[$i]->Phone . " created with id " . $result->id
                . "<br/>\n";
        array_push($ids, $result->id);
    }
}

您看到我想更新自定义字段&#34; contractType__c&#34;,它会引发错误:

Fatal error: Uncaught SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'TypeContrat__c' on entity 'Contact'.
If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. 
Please reference your WSDL or the describe call for the appropriate names.

如果我评论这一行,它会插入记录,我的目的是更新salesforce的自定义字段。抱歉我的英语不好。

谢谢。

Oups!最后的新闻我试图插入没有自定义字段的记录,我也有错误:

stdClass Object ( 
[errors] => Array ( 
[0] => stdClass Object ( 
[message] => ContactBeforeInsert: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.ContactBeforeInsert: line 83, column 1 [statusCode] => CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY ) ) 
[id] => [success] => ) 
stdClass Object ( 
[errors] => Array ( 
[0] => stdClass Object ( 
[message] => ContactBeforeInsert: execution of BeforeInsert caused by: System.NullPointerException: **Attempt to de-reference a null object Trigger.ContactBeforeInsert: line 83**, column 1 [statusCode] => CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY ) ) [id] => [success] => )

1 个答案:

答案 0 :(得分:1)

第一个错误:

根据您的描述,您将收到问题“INVALID_FIELD:实体'联系'上没有此类列'TypeContrat__c'。所以请检查salesforce中此字段的api名称。我认为您在自定义字段的api名称中缺少某些内容接触。

第二个错误:

在您的salesforce组织中,有一个触发器“ContactBeforeInsert”用于联系,并且它获得了一个空指针异常。 (表示他们正在检索某个值,并且为null)。所以请检查一下触发器。按照步骤查看联系人触发器的转到设置列表 - >自定义 - &gt;联系 - &gt;触发。