You need to sign in to do that
Don't have an account?
Becky Hammond 6
OppTerrAssignDefaultLogicFilter Help needed
Hi All - I'm hoping someone can help. I've deployed the class at the following link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_TerritoryMgmt_OpportunityTerritory2AssignmentFilter.htm
I'm using this to assign opportunities. All of our accounts have exactly one opportunity. When I run the opportunity filter, it is assigning 165 out of 629 opportunities. If I run it again, it assigns 464 opportunities and leaves 165 unassigned. Has anyone experienced this? Salesforce support told me my only option is to look for help here as we are not a premier customer.
Thanks for any help you can provide.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_TerritoryMgmt_OpportunityTerritory2AssignmentFilter.htm
I'm using this to assign opportunities. All of our accounts have exactly one opportunity. When I run the opportunity filter, it is assigning 165 out of 629 opportunities. If I run it again, it assigns 464 opportunities and leaves 165 unassigned. Has anyone experienced this? Salesforce support told me my only option is to look for help here as we are not a premier customer.
Thanks for any help you can provide.
What I would do is to start putting System.Debug(variable) statements all over your code to start seeing how the code is working and how it's assigning things. Normally what ends up happening is some weird piece of data somewhere that is throwing things off.
Do some log capturing (System.Debug statements) and analysis - come back here if you have questions and we can try to help!
if((tp != null) )
//&& (tp.territory2Id != opp.Territory2Id))
//&& (tp.moreTerritoriesAtPriority == false)
{
OppIdTerritoryIdResult.put(opp.Id, tp.territory2Id);}
else{
OppIdTerritoryIdResult.put(opp.Id, null);
}
}
}
return OppIdTerritoryIdResult;
}
In that piece above, we commented out the criteria that checks the territory priority. All of our accounts have only one territory but for some reason those two lines were acting like a toggle to assign and unassign the same opportunities. Any thoughts?
Thanks for the help Becky. I look forward to an update to the code.
Seems to me that the second condition tp.territory2Id != opp.Territory2Id is the toggle.
If your Opp is on Territory A and the Account higgest ranked Territory is A this will be false and you'll go to the else part which remove the territory from the Opportunity (set to null)
I will remove this condition.
The last condition tp.moreTerritoriesAtPriority == false means that if there is only one territory associated with your Account (which is higgest ranked) then you'll assign the territory to the Opportunity
If your Account has 2 Territories A and B with Rank 1 and no higger ranked territory, moreTerritoriesAtPriority will be true and you'll also remove the territory from the Opportunity
But we should only comment out the tp.territory2Id != opp.Territory2Id thing as that is what removes the territory from the opps which already have been assigned territories correctly. But since it goes into the else part, it removes the territories assigned. Commenting this line resolves it.
All other code looks correct and should handle for both scenarios, a) for accounts having one territory b) for accounts having multiple territories
Please mark this answer as solution if it helps you.