Hello everyone!, I am trying to automate territory assignment rules execution after each account update. Looking around I found this blog: https://www.jitendrazaa.com/blog/salesforce/enterprise-territory-management-auto-account-assignment-using-apex/
And also this app from appexchange: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N4V00000HIoNoUAL&tab=r
But both have the same issue, they keep executing api calls and reach the org API Calls Limit really quick.
Has anyone found or developed a working solution for this?.
I would really appreciate any help. Thanks a lot!!1 risposta
Hello Robin,I would request you to please find below the article with the help of which you can try to run territory assignment rules on account update :https://help.salesforce.com/s/articleView?id=sf.tm2_assign_accounts_to_territories.htm&type=5As mentioned on the blog link which you have shared https://www.jitendrazaa.com/blog/salesforce/enterprise-territory-management-auto-account-assignment-using-apex/,Using Territory Management in Salesforce, we can auto assign territories to Account and give access to users working in common region. When we create Account, Territory Assignment rules automatically runs. On Account update we have a checkbox on page layout allowing to run Territory rules. However, Lightning experience does not support Territory Assignment checkbox yet on page layouts.Unfortunately, Apex also does not support Account Assignment using Territory rules. Only way left is to use Salesforce API. Question is, just to run Enterprise Territory Management rules, should we import WSDL and convert it to respective Apex classes ? There must be some better way.Additionally ,If you are updating accounts via API, you need to specify the AssignmentRuleHeader header with the value useDefaultRule=true. This will ensure that the default (active) territory assignment rule is applied to the account update.Here is an example of how to specify the AssignmentRuleHeader header when updating an account via API:PUT /services/data/v52.0/sobjects/Account/{accountId} HTTP/1.1 Authorization: Bearer YOUR_ACCESS_TOKEN Content-Type: application/json { "Name": "My Account", ... } AssignmentRuleHeader: useDefaultRule=truePlease mark this as a best answer if this helps.Thank You!