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
-
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.
-
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!
-
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!
-
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.
-
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.
-
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
Similar Threads
-
By quantentunnel in forum Salesforce Coding Discussions
Replies: 4
Last Post: 04-09-2011, 05:46 AM
-
By ncee in forum Salesforce Coding Discussions
Replies: 2
Last Post: 12-09-2008, 02:52 PM
-
By smit1626 in forum Salesforce Coding Discussions
Replies: 1
Last Post: 04-21-2008, 08:03 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
Bookmarks