Update: The original question was missing some crucial details which were responsible for the issue, so they have been added in and are marked as part of the update.
Original Question
I'm working on an API that submits leads and associated objects to Salesforce via the Salesforce REST API using the composite request endpoint.
Issue
When inserting a lead as part of a composite subrequest the assignment rules are running but owner is not correctly assigned.
Example
In early subrequests we're making GET requests to retrieve objects and then using their values in later object creation.
Here's a rough example of how the composite request body:
{
"allOrNone": false,
"compositeRequest": [
{
"referenceId": "refAccount",
"method": "GET",
"url": "/services/data/v48.0/sobjects/Account/[account-id]?fields=Country__c,Lead_Record_Type_Id__c",
"body": null
},
{
"referenceId": "refLead",
"method": "POST",
"url": "/services/data/v48.0/sobjects/Lead",
"body": {
"FirstName": "TestLead",
"LastName": "QueueTest",
"Country__c": "@{refAccount.Country__c}",
"RecordTypeId": "@{refAccount.Lead_Record_Type_Id__c}",
},
"httpHeaders": {
"Sforce-Auto-Assign": "TRUE"
}
}
]
}
The value of refLead.Country__c
is being replaced by the value of refAccount.Country__c
.
An example of a similar rule criteria to what we are using looks like:
ISPICKVAL( Country__c , "UK") && ISPICKVAL( Other_Lead_Field__c , "Other Value")
Updated: An additional check for the value of Other_Lead_Field__c
has been added to the rules example. This field is not included in the initial submission as its value is automatically set by workflow rules.
When we make a submission where the value of refAccount.Country__c
is "UK"
we are finding that this rule is not applied.
Is it possible that the rules are being applied before values are replaced in the composite request?