I am new to using the salesforce api. I have downloaded the saleforce/php toolkit and am able to successfully create contacts and accounts from a webform on my server.
To create a contact I am doing the following:
$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');
To create an account I am doing the following
$records[0] = new stdclass();
$records[0]->Name = $Name
$create = $mySforceConnection->create($records, 'Account');
Can anyone give me a simple example of how I would associate a contact with an account?
I have a check-box on the form that asks if this is an organization. If the user checks this box I would like to create an organization account with some of the data and create contact with some of the data and associate the two.
I am not looking for a full-blown working example but more just something pointing me in the right direction.
Let's say I have an account with the id of 001Z0000004XeWfIAK
I have tried
$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');
it returns this:
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] =>
)
)
But I am trying to associate a contact with an organization.