2

Is there anyway to reference an account recordtype by Name when creating an account using Composite API which has recordtypes? I am hoping there is a way so I don't need to do a get request to get a RecordTypeId and associate it with my accounts.

enter image description here

2

Yes, you simply build a reference object, like this:

"RecordType": { "attributes": { "sobjectType": "RecordType" }, "Name": "Household" }

Of course, this will fail if the user doesn't have access to the record type, or if more or less than one record type has this exact name for this object.

This works anywhere that you could put a RecordTypeId attribute, including insert/update commands, composite commands, sobject tree commands, etc.


If you're getting duplicate record errors, you can run a query to get the record you need first. Here's an example composite request that does this:

{
    "allOrNone": true,
    "compositeRequest": [
        {
            "url": "/services/data/v44.0/query?q=select+Id+from+recordtype+where+sobjecttype=%27account%27+and+name=%27household%27",
            "method": "GET",
            "referenceId": "recType"
        },
        {
            "url": "/services/data/v44.0/sobjects/Account",
            "method": "POST",
            "referenceId": "householdAccount",
            "body": {
                "Name": "John Doe Family",
                "RecordTypeId": "@{recType.records[0].Id}"
            }
        }
    ]
}
  • Thank you! I had trouble finding info on that. – DerrickE Nov 13 '18 at 18:52
  • Hello sfdcfox. I do have the same recordtype name "General" which is used on account and another recordtype "General" used on contact. So from what I understand this will always Error? I was referencing the sobject type "RecordType": { "attributes": { "sobjectType": "Account" }, "Name": "General" } but I am getting a Duplicate Failure – DerrickE Nov 13 '18 at 19:12
  • @DerrickE yes, you can get duplicate errors in this case. I added an example of how to query the record type without having to make round trips to the server. This may help you without needing to rename a record type. – sfdcfox Nov 13 '18 at 19:40
  • Thank you for your help. Yah I wanted to avoid using a get request because each upsert can be different record types and trying to just upsert them regardless of what recordtype. I may just change the recordtype name. – DerrickE Nov 13 '18 at 19:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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