2012-02-09 115 views
7

我是使用salesforce API的新手。我已經下載了saleforce/php工具包,並能夠在我的服務器上成功創建聯繫人和帳戶。與使用salesforce API的帳戶關聯聯繫

要創建聯繫人,我做了以下內容:

$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'); 

誰能給我的我怎麼會關聯一個簡單的例子聯繫一個賬戶?

我有一個窗體上的複選框,詢問這是否是一個組織。如果用戶選中此框,我想創建一個包含部分數據的組織帳戶,並與部分數據建立聯繫並關聯這兩個數據。

我不是在尋找一個完整的工作例子,而是更多的東西指向我在正確的方向。

可以說我有001Z0000004XeWfIAK

的ID

我已經試過

$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'); 

@ superfell帳戶

它返回:

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

聯繫人是否已創建?你有任何錯誤? – 2012-02-09 22:05:00

+0

您需要使用示例$ create來查看創建失敗的原因。 – superfell 2012-02-09 22:19:28

+0

對不起。我不認爲我很清楚。我有一個名爲組織的帳戶類型。每個組織都有與之相關的聯繫人。我試圖將聯繫人與組織關聯 – jpshayes 2012-02-09 22:30:27

回答

6

好的,我自己回答,因爲我不能將Superfell評論標記爲答案。但是,他的評論

「當你創建帳戶,您需要設置recordTypeId達到創紀錄的類型,這不是家庭RECORDTYPE - 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的成功返回的消息與新的AccountID

 
Array 
(
    [0] => stdClass Object 
     (
      [id] => 001Z0000004XfXcIAK 
      [success] => 1 
     ) 

) 

然後我可以創建聯繫人並將它與我的新帳戶關聯

$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'); 

再次感謝Jeremey和Superfell。節省了我的時間。

6

聯繫人有一個AccountId字段。因此,下面的代碼假設您在名爲$accountId的變量中具有帳戶ID,$resource[0]是您想要關聯的聯繫人。

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

我不知道PHP很好,但我認爲這將是接近正確的。

+0

謝謝傑瑞美。我相信我已經嘗試過。我更新了我的問題 – jpshayes 2012-02-09 21:41:05

+0

除了通過AccountId之外,沒有其他關聯,但必須先創建帳戶,以便您可以在Contact.AccountId中使用其Id。你得到的是一個自定義的驗證錯誤,需要與帳戶/聯繫人記錄類型匹配,檢查驗證規則並分配適當的記錄類型 – mmix 2012-02-10 14:17:59

相關問題