Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用salesforce api将联系人与帐户关联_Php_Api_Salesforce - Fatal编程技术网

Php 使用salesforce api将联系人与帐户关联

Php 使用salesforce api将联系人与帐户关联,php,api,salesforce,Php,Api,Salesforce,我不熟悉使用salesforce api。我已经下载了saleforce/php工具包,并且能够从服务器上的Web表单成功创建联系人和帐户 要创建联系人,我将执行以下操作: $records[0] = new stdclass(); $records[0]->FirstName = $FirstName; $records[0]->LastName = $LastName; $records[0]->Email = $Email; $re

我不熟悉使用salesforce api。我已经下载了saleforce/php工具包,并且能够从服务器上的Web表单成功创建联系人和帐户

要创建联系人,我将执行以下操作:

    $records[0] = new stdclass();
    $records[0]->FirstName = $FirstName;
    $records[0]->LastName = $LastName;
    $records[0]->Email = $Email;
    $records[0]->Phone = $Phone;
    $records[0]->MailingStreet = $MailingStreet;
    $records[0]->MailingCity = $MailingCity;
    $records[0]->MailingState = $MailingState;
    $records[0]->MailingPostalCode = $MailingPostalCode;
    $records[0]->MailingCountry = $MailingCountry;
    $records[0]->LeadSource = $LeadSource;

    $create = $mySforceConnection->create($records, 'Contact');
要创建帐户,我将执行以下操作

    $records[0] = new stdclass();
    $records[0]->Name = $Name

    $create = $mySforceConnection->create($records, 'Account');
有谁能给我一个简单的例子,告诉我如何将联系人与帐户联系起来

我在表格上有一个复选框,询问这是否是一个组织。如果用户选中此框,我希望使用一些数据创建一个组织帐户,使用一些数据创建一个联系人,并将两者关联起来

我不是在寻找一个完整的工作示例,而是在寻找一个能为我指明正确方向的东西

假设我有一个id为001Z0000004XeWfIAK的帐户

我试过了

    $records[0] = new stdclass();
    $records[0]->FirstName = $FirstName;
    $records[0]->LastName = $LastName;
    $records[0]->Email = $Email;
    $records[0]->Phone = $Phone;
    $records[0]->MailingStreet = $MailingStreet;
    $records[0]->MailingCity = $MailingCity;
    $records[0]->MailingState = $MailingState;
    $records[0]->MailingPostalCode = $MailingPostalCode;
    $records[0]->MailingCountry = $MailingCountry;
    $records[0]->LeadSource = $LeadSource;
    $records[0]->AccountId = '001Z0000004XeWfIAK';

    $create = $mySforceConnection->create($records, 'Contact');
@超级电池

它返回以下内容:

Array ( [0] => stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [message] => A Household Contact's account must be a household. [statusCode] => FIELD_CUSTOM_VALIDATION_EXCEPTION ) ) [id] => [success] => ) ) 排列 ( [0]=>stdClass对象 ( [错误]=>数组 ( [0]=>stdClass对象 ( [消息]=>家庭联系人的帐户必须是家庭。 [statusCode]=>字段\自定义\验证\异常 ) ) [id]=> [成功]=> ) )
但我试图将联系人与组织关联

联系人有一个
AccountId
字段。因此,下面的代码假设您在名为
$accountId
的变量中有帐户id,
$resource[0]
是您要关联的联系人

$records[0]->AccountId = $accountId
$mySforceConnection->update($records)

我不太懂php,但我认为这几乎是正确的。

好的,我自己回答这个问题,因为我不能将Superfell评论标记为答案。但是他的评论


“创建帐户时,需要将recordTypeId设置为非家用记录类型的记录类型。–superfell”

帮我找到了答案

这是我创建帐户的最终代码,然后是该帐户的联系人

    //First I create a simple account
    //With no recordTypeId specified it defaults to the the type I want

    $records[0] = new stdclass();
    $records[0]->Name = $Name;

    //Create a new orginization account
    $org = $mySforceConnection->create($records, 'Account');
创建帐户后,Salesforce返回一条带有新帐户ID的成功消息

Array ( [0] => stdClass Object ( [id] => 001Z0000004XfXcIAK [success] => 1 ) )
再次感谢Jeremey和Superfell。节省了我的时间。

谢谢杰里米。我相信我已经试过了。我在上面更新了我的问题除了通过AccountId没有其他关联,但是必须首先创建帐户,以便您可以在Contact.AccountId中使用它的Id。您得到的是一个自定义验证错误,要求帐户/联系人的记录类型匹配,请检查验证规则并分配适当的记录类型是否创建了联系人?您是否有任何错误?您需要查看$create示例以了解创建失败的原因。对不起。我想我说的不清楚。我有一个名为organization的帐户类型。每个组织都有与其相关的联系人。我正在尝试将联系人与组织关联创建帐户时,需要将recordTypeId设置为非家庭记录类型的记录类型。
    $contact[0] = new stdclass();
    $contact[0]->FirstName = $FirstName;
    $contact[0]->LastName = $LastName;
    $contact[0]->Email = $Email;
    $contact[0]->Phone = $Phone;
    $contact[0]->MailingStreet = $MailingStreet;
    $contact[0]->MailingCity = $MailingCity;
    $contact[0]->MailingState = $MailingState;
    $contact[0]->MailingPostalCode = $MailingPostalCode;
    $contact[0]->MailingCountry = $MailingCountry;
    $contact[0]->LeadSource = $LeadSource;

    //This is where my problem was, Thanks again superfell
    //$organization_contact = My custom Salesforce contact type ID, E.G. recordTypeId
    $contact[0]->recordTypeId = $orginization_contact;

    //The AccountId is the account I want to associate this contact with.
    //AccountId was returned by Salesforce upon the creation of the account (See above)  
    $contact[0]->AccountId = $org[0]->id;

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