+ Start a Discussion

How to change Opportunity's Territory using an S-Control?

We need to explicitly set the Territory of an Opportunity to a specific Territory.

Is this possible?  It seems there is a lot of special rules and processing for assigning Territories to Opportunities.  Is there a way to do this in a custom way by bypassing/overriding/cooperating with the special processing related to Territories-Opportunities?

This was solved by a response to the same question in another discussion: AJAX  Toolkit & S-controls.  Here's a copy of the post by sfdcfox that helped us out (thanks again sfdcfox):


If you know the territory you wish to assign to the opportunity by ID, you can use that ID (this is an AJAX version, adjust to suit your language preference):

Opportunity = new sforce.SObject("Opportunity")
Opportunity["Id"] = "{!Opportunity.ID}"
Opportunity["TerritoryId"] = "<sfdc territory id here>"


Normally, though, these are assigned based on the rules you've specified, as defined by the User/Account Territory matrix (eg. if there is one common territory between user and account, the opportunity inherits that territory). But this would allow you to override the territory as you needed to.

~ sfdcfox ~