• Miguel Bayón
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 1
    Questions
  • 4
    Replies
I need to show a picklist in a visualforce with all the related territories of an user. These territories are the user's assigned territories and all the territories under them in the territory hierarchy. For example, with a hierarchy like this one:
Europe
 |- France
 |- Spain <--
   |- Madrid
   |- Catalunya
     |- Barcelona
 |- Italy
A user assigned to Spain should see Madrid, Catalunya and Barcelona as possible options in the picklist. Right now I achieve this using a recursive function, but in a production org with around 1300  territories, I'm hitting CPU and SOQL limits all the time because I need to execute a SOQL query for every sub territory.

Reading Enterprise Territory Management documentation I cannot find any function provided by Salesforce to achieve this and the object itself doesn't have a named relationship between the parent a its sons that could help me reduce the number of queries. I was looking something like this:
SELECT Id, Name, (SELECT Id, Name FROM ChildTerritory2s) FROM Territory2 WHERE DeveloperName = 'Spain'
Hope someone have some workaround for achieving this without using something as demanding as a recursive function that when it hits the limits doesn't show the end of the list. Thanks.
I need to show a picklist in a visualforce with all the related territories of an user. These territories are the user's assigned territories and all the territories under them in the territory hierarchy. For example, with a hierarchy like this one:
Europe
 |- France
 |- Spain <--
   |- Madrid
   |- Catalunya
     |- Barcelona
 |- Italy
A user assigned to Spain should see Madrid, Catalunya and Barcelona as possible options in the picklist. Right now I achieve this using a recursive function, but in a production org with around 1300  territories, I'm hitting CPU and SOQL limits all the time because I need to execute a SOQL query for every sub territory.

Reading Enterprise Territory Management documentation I cannot find any function provided by Salesforce to achieve this and the object itself doesn't have a named relationship between the parent a its sons that could help me reduce the number of queries. I was looking something like this:
SELECT Id, Name, (SELECT Id, Name FROM ChildTerritory2s) FROM Territory2 WHERE DeveloperName = 'Spain'
Hope someone have some workaround for achieving this without using something as demanding as a recursive function that when it hits the limits doesn't show the end of the list. Thanks.
I followed all process of linking to trailhead, trailhead account is verified but badges are not showing there.
Please help on this.
Although I have connected my Trailhead Account within my Partner Community Profile, none of my Trailhead Badges are shown there. What can I do?
I followed all process of linking to trailhead, trailhead account is verified but badges are not showing there.
Please help on this.
Although I have connected my Trailhead Account within my Partner Community Profile, none of my Trailhead Badges are shown there. What can I do?