...
Code Block | ||
---|---|---|
| ||
path = "/services/data/42.0" // On Update of an existing Contact's details or creation of a new Contact //If SFContactID is blank { "method" : "PATCH", "url" : path + "/sobjects/Account/UniqueID__c/ABCEnterprisesNSW", //Company Name+(Billing Address State or Other State) with spaces stripped out then trimmed to 255 chars "referenceID" : "refNewAccount", "body" : { "Name" : "ABC Enterprises", //Company "BillingStreet" : "15 Smith Street", //Billing Address - Street "BillingCity" : "Smithville", //Billing Address - Suburb "BillingState" : "NSW", //Billing Address - State or Other State "BillingPostalCode" : "2656", //Billing Address - Postcode "BillingCountry" : "Australia", //Billing Address Country "Phone" : "02 9898 9898" //Business Phone } }, //Now get that Account ID just created or updated { "method" : "GET", "url" : path + "/sobjects/Account/@{refNewAccount.id}", "referenceId" : "refNewAccountInfo" }, // Now Create or Update the Contact { "method" : "PATCH", "url" : path + "/sobjects/Contact/UniqueID__c/JaneDoejdoe@gmail.com", //First Name + Surname + Email Address with spaces striped out then trimmed to 255 chars "referenceId" : "refNewContact", "body" : { "Saluation" : "Ms", //Title "FirstName" : "Jane", //First Name "LastName" : "Doe", //Surname "Title" : "Director", //Position "Email" : "jdoe@gmail.com", //Email Address "AccountId" : "@{NewAccountInfo.Id}", "MailingStreet" : "@{NewAccountInfo.BillingStreet}", "MailingCity" : "@{NewAccountInfo.BillingCity}", "MailingState" : "@{NewAccountInfo.BillingState}", "MailingPostalCode" : "@{NewAccountInfo.BillingPostalCode}", "MailingCountry" : "@{NewAccountInfo.BillingCountry}", "Phone" : "@{NewAccountInfo.Phone}", "MobilePhone" : "04085608409908960940" //Mobile } }, //Now get that Contact ID just created or updated { "method" : "GET", "url" : path + "/sobjects/Contact/@{refNewContact.id}", "referenceId" : "refContactInfo" }, // Update that into your SFContactID field on the website |
...
- Doing a GET on an id returns the whole object, not just the ID
- "method" : "GET",
"url" : "/services/data/v41.0/sobjects/Contact/@{refNewContact.id}",
"referenceId" : "refContactInfo"
- "method" : "GET",
Solution
- So you have to do a GET with a query in the middle of the two PATCH methods.
- AND you can't use {{@{refNewAccount.id}}} syntax, you have to use the extended query syntax.
- So this is what finally worked!
Code Block |
---|
{ "compositeRequest" : [ { "method" : "PATCH", "url" : "/services/data/v41.0/sobjects/Account/UniqueID__c/ABCEnterprisesNSW", "referenceId" : "refNewAccount", "body" : { "Name" : "ABC Enterprises", "BillingStreet" : "15 Smith Street", "BillingCity" : "Smithville", "BillingState" : "NSW", "BillingPostalCode" : "2656", "BillingCountry" : "Australia", "Phone" : "02 9898 9898" } }, { "method" : "GET", "url" : "/services/data/v41.0/query/?q=select+id,name,Industry,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,Phone+from+Account+where+UniqueID__c='ABCEnterprisesNSW'", "referenceId" : "refNewAccountInfo" }, { "method" : "PATCH", "url" : "/services/data/v41.0/sobjects/Contact/UniqueID__c/JaneDoejdoe@gmail.com", "referenceId" : "refNewContact", "body" : { "Salutation" : "Ms", "FirstName" : "Jane", "LastName" : "Doe", "Title" : "Director", "Email" : "jdoe@gmail.com", "AccountId" : "@{refNewAccountInfo.records[0].Id}", "MailingStreet" : "@{refNewAccountInfo.records[0].BillingStreet}", "MailingCity" : "@{refNewAccountInfo.records[0].BillingCity}", "MailingState" : "@{refNewAccountInfo.records[0].BillingState}", "MailingPostalCode" : "@{refNewAccountInfo.records[0].BillingPostalCode}", "MailingCountry" : "@{refNewAccountInfo.records[0].BillingCountry}", "Phone" : "@{refNewAccountInfo.records[0].Phone}", "MobilePhone" : "9908960940" } }, { "method" : "GET", "url" : "/services/data/v41.0/query/?q=select+id+from+Contact+where+UniqueID__c='JaneDoejdoe@gmail.com'", "referenceId" : "refNewContactId" }] } |