function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adrian MonzonAdrian Monzon 

Lead Assignment rules not working with REST API

Hi there,

I'm using REST API to post data to Salesforce. However, the Lead Assigment rules we've created don't work even if the criteria have been met.
Karan Shekhar KaulKaran Shekhar Kaul
Hi Adrian,

Are you using standard Lead creation API provide by Salesforce or custom Apex Rest service?

Standard REST API :Set Assignment header 
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_assignmentruleheader.htm
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_lead.htm#topic-title

Custom APEX REST: Add below code

Database.DMLOptions dmo = new Database.DMLOptions(); d
mo.assignmentRuleHeader.useDefaultRule = true;
dmo.OptAllOrNone = false;

 
Kevin McaloonKevin Mcaloon
So the OP is trying to use the REST API, not SOAP or APEX. 

Many people have posted similar issues without any clear solutions I can see.  The following header is supposed to give us more control over lead assignments via the REST API, but no matter what does not seem to work with leads: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_autoassign.htm.  Maybe OP can have some better luck with it than I have.
 
FilikinFilikin
Kavan's solution worked for me - thanks
Emma BindiEmma Bindi
Kavan's solution worked for me to thank you!
(I am creating new Leads through custom Apex REST post service and assignment rules were not activating until using the above)