I need to assign Accounts in different Territories based on the criteria rule when inserting or updating Accounts from Data Loader.

In Data Loader we have to provide the assignment rule Id to execute the rule but I have more than one rules and in data loader we can provide only one id at a time.

Can someone help me how I can execute all rules.



I know this is very old post. But want to give a solution so other can solve this issue. Yes this is possible to run territory assignment rule.

What you need to use SOAP API for firing the territory management rule. You can pass the same org's credentials(which you are using).

Use this class TerritoryMangRule.fireTerritoryManagementViaSoap(Pass list of Account here).

Follow the steps in link to generate WSDL https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts

So Once trigger is fired call a future method from trigger to execute the webservice and pass all the Accounts.

global class TerritoryMangRule
    webService static void fireTerritoryManagementViaSoap(List<Account> lstAccountToUpdate) 
        partnerSoapSforceCom.Soap obj = new partnerSoapSforceCom.Soap();
        partnerSoapSforceCom.LoginResult loginResult = obj.login('org@username.com', 'Password');   
        obj.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();
        obj.endpoint_x =loginResult.ServerUrl;
        obj.Sessionheader.sessionid = loginResult.sessionid;
        List<sobjectPartnerSoapSforceCom.sObject_x> lst = new List<sobjectPartnerSoapSforceCom.sObject_x>();
        for(Account ac:lstAccountToUpdate)
            sobjectPartnerSoapSforceCom.sObject_x tmpObj = new sobjectPartnerSoapSforceCom.sObject_x();
            tmpObj.type_x = 'Account';
            tmpObj.Id = ac.Id;
        partnerSoapSforceCom.AssignmentRuleHeader_element  obj1 = new partnerSoapSforceCom.AssignmentRuleHeader_element();
        obj1.useDefaultRule = true;
        obj.AssignmentRuleHeader = obj1;
        partnerSoapSforceCom.SaveResult[] lst1 =obj.update_x(lst);

We just need to perform dummy update(Including set AssignmentRuleHeader) via SOAP API. It will run the Territory management rule.

| improve this answer | |

When you insert Accounts from data loader no way you can run territory assignment rule

Also as you mentioned you can run only one rule during update of account only.

One way you could do is write your own code in Java/.NET to do this activity

Setting Assignment Rule Header

And some help from the below link


| improve this answer | |

We can run Territory Assignment Rule on insert or update of Accounts by Data Loader. We need to provide the any of the assignment rule id in the setting of Data Loader and it will execute all the other assignment rule of Territory automatically.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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