0

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.

6
  • How are you calling this function, on a visualforce page?
    – Girbot
    Oct 25, 2018 at 16:48
  • Not sure what you mean by visualforce. But when a user completes checkout and pays by credit card in the storefront, it calls $salesforce->createContact(); and then calls another function to add that contact to the opportunity.
    – gabessdsp
    Oct 25, 2018 at 18:55
  • Are you getting back an error from the Salesforce API? The 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.
    – David Reed
    Oct 30, 2018 at 19:13
  • This wasn't apparent in the documentation, so I dumped the $response and I see that I am getting an error for the IsDeleted field. When I removed field my response wasn't showing any errors, but now it doesn't create the contact role at all which is why I thought the IsDeleted field had to be included in there. I'm trying to look over the error handling in Salesforce API and I'm not sure how I'm supposed to check for an error, and return it to me. Can you provide any help in that area?
    – gabessdsp
    Oct 31, 2018 at 12:48
  • How are you determining that the contact role is not created? I don't speak PHP so I can't provide any insight on that specific Salesforce connector.
    – David Reed
    Oct 31, 2018 at 19:00

1 Answer 1

0

Well today I found the solution to my own question. It appears I cannot set the IsPrimary function on the AccoutnContactRole level but instead I had to place it when adding the contact to the opportunity at the OpportunityContactRole level.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .