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
krishna3krishna3 

TERRITORY ASSIGNMENT RULES ISSUE

Hi everyone,

 

can anyone help me out how to solve the issue.

 

we have territory management is enable on our environment.

 

when we create Accounts teritory rules will run and the Account will assign to particular user based on the Zipcode we enterted.

 

same need to happen when we edit the record and change the zipcode, but its not happening while editing the records.

 

can this be solve by trigger or apex job??

 

thanks in Advance :smileyhappy:

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Just so we're clear on this subject... you can only run Territory Assignment rules when using the default page, not a Visualforce page. Maybe at some point in the future, you'll be able to do this, but it's not supported today.

All Answers

sfdcfoxsfdcfox

You need to check the "Run territory management rules on save" in order to run the rules on an existing account. You can configure the visibility and default state of this box on the page layout (see Edit Layout in the upper-right corner when viewing any account).

krishna3krishna3

Thanks for the reply.

 

i forgot to mention that we created a vf page and ovveride the edit page with that vf page.

 

so can you suggest me how can we do that..

 

thanks again.

sfdcfoxsfdcfox

It's currently not supported (as far as I can tell). You have to use the default page to run rules. There is something called Database.DMLOptions, but it doesn't currently support account assignment/territory rules.

krishna3krishna3

Thanks for the reply,

 

can we do that after insert or update the trigger.....on save button

sfdcfoxsfdcfox

Just so we're clear on this subject... you can only run Territory Assignment rules when using the default page, not a Visualforce page. Maybe at some point in the future, you'll be able to do this, but it's not supported today.

This was selected as the best answer
krishna3krishna3

thanks for the solution, 

but we can run the TM rules using webservices API.

 

sfdcfoxsfdcfox

I know. That's one of the (many) disparities between Apex Code and the Web Service API. Apex Code doesn't fully support all facets of the Web Service API that Force.com offers, at least not yet. You'll have to accept that as a limitation of what you're trying to do.

 

As a workaround, you could consider having your page perform its duty, and then redirect to an auto-save URL, such as /{!Account.Id}/e?save=x&runterritoryrules=x (I don't know the name of the "run rules on save" flag, so you'll have to look it up). Alternatively, you could use the AJAX Toolkit (see /soap/ajax/21.0/connection.js) as part of your page's logic; you can invoke the API using this JavaScript, and it will support all of the headers, including the territory assignment header.

hamayoun65hamayoun65

Is there anyway of doing this from a batch process?  Can you somehow call a URL to salesforce from within a batch process?

sfdcfoxsfdcfox

I apologize for not responding sooner, but I missed this reply in my inbox. You can indeed use a HTTP request to call back to the server. I presume that this would probably work if you had the correct URL. It is also possible to get the Session ID within Apex Code, which you would need to complete the transaction. This method certainly is not supported, but I don't see why it wouldn't work if you were so inclined to track down the steps needed to make it happen. Thinking back on this, you could also call the page through VF or even a normal class, but again, being an unsupported function, I'm not sure how well this would work. The major hassle is that you'd have to puzzle together all the parameters required to make the solution work, which may make it more trouble than its worth.