+ Start a Discussion
echolane.ax304echolane.ax304 

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?
sfdcfoxsfdcfox
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>" sforce.connection.update([Opportunity]) 
Presto!

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 ~
echolane.ax304echolane.ax304
Thanks a zillion!  It was exactly what we needed and it helped us solve our problem perfectly. *****