4

Background

I'm currently trying to create a User and PersonAccount at the same time. In order to do that I send the following Payload to the composite API Endpoint:

{
    "compositeRequest":[
        {
            "method":"POST",
            "url":"/services/data/v38.0/sobjects/Account",
            "referenceId":"refAccount",
            "body":{
                "Lastname":"SampleAccount",
                "RecordTypeId":"0125E000000T8IGQA0"
            }
        },
        {
            "method":"POST",
            "url":"/services/data/v38.0/sobjects/User",
            "referenceId":"refUser",
            "body":{
                "lastname":"Smith",
                "ContactId":"@{refAccount.PersonContactId}",
                "title":"President",
                "email":"sample@salesforce.com",
                "Username":"sa111mple@salesforce.com",
                "TimeZoneSidKey":"",
                "ProfileId":"00e1i0000013UvI",
                "Alias":"abc",
                "LanguageLocaleKey":"DE",
                "TimeZoneSidKey":"Europe/Dublin",
                "LocaleSidKey":"DE",
                "EmailEncodingKey":"ISO-8859-1"
            }
        }
    ]
}

Result

errorCode: PROCESSING_HALTED message: Invalid reference specified. No value for refAccount.PersonContactId found in refAccount

Question

Is there any way to create a User and PersonAccount in the same request? (Except Custom APEX or Trigger)

4
+50

for this you need to include a GET method to fetch the ID of the record created and ref that in your following POST method. Below is the payload i modified, try this. I'm positive it will work.

Side note: If you only have to create records and there isn't a need to do any kind of updates, you probably want to look at Composite TREE API which is a much simpler payload and you don't have to specify your methods in it or need to add a GET method to ref the Id of the created record

{
    "compositeRequest":[
        {
            "method":"POST",
            "url":"/services/data/v38.0/sobjects/Account",
            "referenceId":"refAccount",
            "body":{
                "Lastname":"SampleAccount",
                "RecordTypeId":"0125E000000T8IGQA0"
            }
        },
{
      "method": "GET",
      "url": "/services/data/v39.0/query/?q=SELECT+Id+FROM+Account+where+Id='@{refaccount.id}'",
      "referenceId": "ref2"
    },

        {
            "method":"POST",
            "url":"/services/data/v38.0/sobjects/User",
            "referenceId":"refUser",
            "body":{
                "lastname":"Smith",
                "ContactId":"@{ref2.records[0].Id}",
                "title":"President",
                "email":"sample@salesforce.com",
                "Username":"sa111mple@salesforce.com",
                "TimeZoneSidKey":"",
                "ProfileId":"00e1i0000013UvI",
                "Alias":"abc",
                "LanguageLocaleKey":"DE",
                "TimeZoneSidKey":"Europe/Dublin",
                "LocaleSidKey":"DE",
                "EmailEncodingKey":"ISO-8859-1"
            }
        }
    ]
}
0

I have not worked with the Composite API, but it appears to create records as per the rest of the REST API, so you should be able to create the person account by setting your account RecordType to a Person Account Record Type, and supplying any of the Person Account fields as needed (FirstName, LastName, etc). From there you should be able to use the PersonContactId generated by the Account insert as the ContactId for your User insert.

  • Hello Jason. In my case I need to perform the user creation and the person account creation in a single request... – Christian Deckert Jun 27 at 13:50
  • I assume by "composite API" you are referring to developer.salesforce.com/docs/atlas.en-us.api_rest.meta/… - this should allow you to use (based on your example) "ContactId" : "@{ref1.PersonContactId}" in the user record. Also be sure you assign the user a community license. – Jason Clark Jun 27 at 14:24
  • I tried it out, it is not working. I've updated the question. – Christian Deckert Jul 1 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.