+ Reply to Thread
Results 1 to 6 of 6
This is a discussion on Creating a Contact related to an existing Account within the Salesforce Coding Discussions forums, part of the Salesforce category; This is a newbie question but cannot be that uncommon. Working through
  1. #1
    scott@pogysoft.com is offline Junior Member
    Join Date
    May 2010
    Location
    Eugene, OR
    Posts
    7

    Creating a Contact related to an existing Account

    This is a newbie question but cannot be that uncommon.

    Working through the PartnerClient of the PHP Salesforce interface, I want to create() a new Contact related to an existing Account. I have tried identifying the related Account by 'Account' => Name and 'Account' => Id, but without success.... I always get back an error in the Account.

    I do not have any trouble looking up the Account Id through a prior query, but wondered just how to use that result to write a related Contact?

    Thanks for any comments.

  2. #2
    Willis's Avatar
    Willis is offline Administrator
    Join Date
    Feb 2010
    Location
    Sunnyvale, CA
    Posts
    19
    Blog Entries
    9
    Hey Scott, thanks for joining the site. Perhaps some more detail would help us out here...

    1.) Do you have another external ID on the Account object? For instance, we have a field called "ASPS ID" which is marked as an External ID.

    2.) Are you inserting the contact detail into the Account Object or the Contact Object?

    The more script you can show the better for us to be able to help you out.


    Looking forward to it!

  3. #3
    scott@pogysoft.com is offline Junior Member
    Join Date
    May 2010
    Location
    Eugene, OR
    Posts
    7

    Re:

    Willis,
    Thanks for replying so quickly!

    >> 1.) Do you have another external ID on the Account object? For instance, we have a field called "ASPS ID" which is marked as an External ID.
    Hmm. Is this error? I am getting the Id from the following codelet and it matches the ID of the page by which I can access the Account (an Organization called ADOPTION INQUIRY):
    <pre>
    $sfconn1 = new SforcePartnerClient();
    $sfconn1->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
    get_salesforce_login($sfconn1);

    $soql = 'SELECT Id FROM Account WHERE Name = \'Adoption Inquiry\'';

    $options = new QueryOptions(100);
    $sfconn1->setQueryOptions($options);
    $response = $sfconn1->query($soql);
    $queryResult = new QueryResult($response);
    $sfconn1->logout();
    $n = count($queryResult->records);
    if ($n > 1 || $n < 1)
    return "ADOPTION INQUIRY QUERY FINDS $n";
    else
    $adoption_inquiry_result_id = $queryResult->records[0]->Id;
    </pre>

    What exactly is the ASPS Id?

    2) I think I am inserting into the Contact object:

    <pre>
    $sfconn2 = new SforcePartnerClient();
    $sfconn2->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
    get_salesforce_login($sfconn2);

    $fields = array (
    'Account' => $adoption_inquiry_result_id,
    'Owner' => 'Christy Obie-Barrett',
    'Description' => '',
    'DoNotCall' => 'false',
    'Email' => $fl->get_username(),
    'HasOptedOutOfEmail' => 'false',
    'FirstName' => $firec->FirstName1,
    'LastName' => $firec->LastName1,
    'Phone' => $firec->HomePhone
    );

    $sObject = new SObject();
    $sObject->fields = $fields;
    $sObject->type = 'Contact';

    $createResponse = $sfconn2->create(array($sObject));
    $sfconn2->logout();
    </pre>

    Any clues appreciated!

  4. #4
    scott@pogysoft.com is offline Junior Member
    Join Date
    May 2010
    Location
    Eugene, OR
    Posts
    7
    Found this problem. The code above is largely correct except that
    the 'Account' needs to be 'AccountID'.
    Owner also needs to be 'Owner_ID' when accessing it from the Contact.
    Since this does not completely agree with Apex Explorer, this is pretty weird... not sure how to know this in advance.

  5. #5
    Willis's Avatar
    Willis is offline Administrator
    Join Date
    Feb 2010
    Location
    Sunnyvale, CA
    Posts
    19
    Blog Entries
    9
    Ah... there you go.

    Yes, the Account and Owner should be the respective IDs. There are a few weird ones like this scattered across Salesforce but generally speaking, if the field on the UI is a lookup, it's probably looking for the ID of the underlying object instead of the name.

    The ASPS ID I was referring to is a specific field in our org and was used only as an example to an external ID. It just makes it easier for us to use 1234 as an ID instead of salesforce.com's 15 character ID.

    Please let me know if you have any other questions.

  6. #6
    mevin is offline Junior Member
    Join Date
    Apr 2009
    Posts
    6
    Hello Willis

    can i have the php code doing an upsert on contact and passing external id of acc for the account field instead of the acc id?
    I need mainly how to associate the external id of acc to acc field?

    Hope to get a reply from you soon

    Regards
    Mevin

+ Reply to Thread

Similar Threads

  1. Upsert Record(s) related to other Objects
    By quantentunnel in forum Salesforce Coding Discussions
    Replies: 4
    Last Post: 04-09-2011, 05:46 AM
  2. Update Contact
    By ncee in forum Salesforce Coding Discussions
    Replies: 2
    Last Post: 12-09-2008, 02:52 PM
  3. Update Contact Description
    By smit1626 in forum Salesforce Coding Discussions
    Replies: 1
    Last Post: 04-21-2008, 08:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.2