I'm not sure why I'm having so much trouble with this. But I've never worked with the Salesforce API and from my understanding, this should be working, but it is not.
I have looked at AccountContactRole to double check the data types etc, but it seems to still be adding the default values to the AccountContactRole when I create the contact.
Here is the function where I have this code.
function createContact(){
$name = $this->contact->billing_name;
$names = explode(" ", $name);
$contact = array();
$contact[0] = new stdclass();
$contact[0]->AccountId = $this->accountId; // Account Name
$contact[0]->FirstName = isset($names[0]) ? $names[0] : "";
$contact[0]->LastName = isset($names[1]) ? $names[1] : "";
$contact[0]->Phone = $this->contact->billing_phone;
$contact[0]->MailingStreet = $this->contact->billing_address1 . " " . $this->contact->billing_address2;
$contact[0]->MailingCity = $this->contact->billing_city;
$contact[0]->MailingState = $this->contact->billing_state;
$contact[0]->MailingPostalCode = $this->contact->billing_zip;
$contact[0]->MailingCountry = $this->contact->billing_country;
$contact[0]->Email = $this->contact->email;
$response = $this->mySforceConnection->create($contact, 'Contact');
if(isset($response[0]->id)){
$this->contactId = $response[0]->id;
}
//ADD account contact as IsPrimary
$acctRole=array();
$acctRole[0] = new stdclass();
$acctRole[0]->AccountId=$this->accountId;
$acctRole[0]->ContactId=$this->contactId;
$acctRole[0]->IsDeleted=false;
$acctRole[0]->Role="Buyer";
$acctRole[0]->IsPrimary=true;
$response = $this->mySforceConnection->create($acctRole, 'AccountContactRole');
if(isset($response[0]->id)){
$this->contactId = $response[0]->id;
}
}
EDIT: I wanted to just update more thoughts on this. I really hope somebody can chime in. This just seems to be ignoring any of the data I have placed inside the array. It write the same information whether I write it or not, why is that? If I fix that, then this should work. I really don't understand why it's not working as-is.
IsDeleted
field cannot be set by you and should produce an exception. You don't seem to be checking for an error, since$this->contactId
should be the contact's Id either way.