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
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?

echolane.ax304echolane.ax304
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):

Code:
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 ~