Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


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"                                
    }]
}

So what that tells us is that once again, Salesforce example code is the simplest code, and you have to go through so many hoops to get even the most basic real world scenario working. But thankfully this post https://developer.salesforce.com/blogs/tech-pubs/2017/01/simplify-your-api-code-with-new-composite-resources.html helped me in the right direction of using the records[0] syntax. 

The next thing I tested is "allOrNone" because I don't want the Account created if it can't create the Contact (because they are the one Contact record on the Website - and remember this is an NFP so we use the 1 to 1 model and create an Account and Contact for the one Contact record. 

allOrNone works like this:

Code Block
{
"allOrNone" : true,
"compositeRequest" : [
	{
       ... 
    }]
}

And returns an error like this

Image Added

So that looks like it will work well. I've asked the Website developer to email me any time there is an error like this, especially during testing phase.