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
John Gallinagh 8John Gallinagh 8 

OpportunityTerritory2AssignmentFilter Global Interface

Recently turned on the Enterprise Territory Management functionality and I'm trying to get the Apex Class setup and keep getting an error message. I've copied the example code from the Apex Developer Guide (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_TerritoryMgmt_OpportunityTerritory2AssignmentFilter.htm#apex_interface_TerritoryMgmt_OpportunityTerritory2AssignmentFilter) and it's not working.  

I keep getting the following error:


No such column 'Territory2Id' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
_Zach Boyd_Zach Boyd
Could you check the API version of the class you are trying to save? I believe it needs to be at least version 33.
John Gallinagh 8John Gallinagh 8
API version 38
_Zach Boyd_Zach Boyd
Odd. I enabled territy management and added the same apex class that you referenced. Everything saved just fine unless I bumped down the API version below 33. The only way I couldn't get the class to save (regardless of API version) and receive the same error you have is if I disabled territory management. Could you validate that it is enabled? Maybe try disabling and re-enabling?
John Gallinagh 8John Gallinagh 8
Still struggling with this.  Any other ideas?
 
John Gallinagh 8John Gallinagh 8
Alight, got past the first issue.  First issue was 100% user error on my part.  Hadn't enabled Enterprise Territory Management in my sandbox environment.  So tests ran fine now with a couple of new failures.  Not sure where to go from here.

Error 1
System.QueryException: List has no rows for assignment to SObject
Stack Trace
Class.IntacctIntegrationContactToContact_Test.testVisualforceContextHappyFlow: line 51, column 1


Error 2
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: a0vd00000095vF2: []

Stack Trace
Class.MassReassignOpportunitiesController.testReassign: line 202, column 1
_Zach Boyd_Zach Boyd
It is hard to tell for both errors without seeing what code is executing. Would you be able to post that?