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
ShaminaShamina 

Run territory assignment rules via Apex or REST API

Hello,

We have configured territory management and implemented a trigger on account object to update a field based on specific conditions. This field is used as a criteria for running territory assignment rules but when the field is updated by the Apex trigger, we have noticed that the territory rules are not evaluated.

According to online documentation and forums, the territory rules are only triggered from the Salesforce interface (if the option "Run territory assignment rules on save" is enabled and visible on page layouts) or from an API call.

With the new release, is it possible to trigger territory assignment rules from Apex and how to implement it ?

 

If its not possible from Apex, can you please provide some sample PHP codes to run the rules via REST API ?

 

Sumit@TCSSumit@TCS
Hi ,

Did you get the answer for this.
I am also stuck for the same.

Let me know how you fix that ASAP
ShaminaShamina
Hello,

This is still an issue according to this post: https://success.salesforce.com/ideaview?id=08730000000BqRXAA0

In my case, I ended up developing a trigger in salesforce that sets a boolean flag on account on certain conditions. Then there is an external SOAP api call that is executed in PHP, that updates this flag again on account while applying "useDefaultRule" option to the AssignmentRuleHeader. This header option allows the territory rules to be executed again on update of the account boolean flag
$header = new AssignmentRuleHeader(null, true);
$this->sfdc->setAssignmentRuleHeader($header);

For more information about this header attribute :
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_assignmentruleheader.htm?search_text=useDefaultRule
https://community.informatica.com/ideas/1094

Hope this helps