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
ipsips 

"is territory enabled?" check using apex

Hi,

    Is there any way to check whether territory is enabled or not in current org using apex (programmatically)?

 

 

Thanks in advance...

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You can use a Schema.getGlobalDescribe() and check for the presence of the Territory object, or you could use a try-catch block on an account to programmatically check for the presence of a Territory field (using Dynamic Apex).

All Answers

sfdcfoxsfdcfox

You can use a Schema.getGlobalDescribe() and check for the presence of the Territory object, or you could use a try-catch block on an account to programmatically check for the presence of a Territory field (using Dynamic Apex).

This was selected as the best answer
ipsips

Thanks for a reply. But is there any field on Standard object (e.g. Organization) that tells whether  territory enabled on org?

sfdcfoxsfdcfox

There's no way to easily detect any "addon" feature (multi-currency, translation workbench, territory management, etc) short of checking for the presence of an object unique to that feature. If you directly reference the object (e.g. Territory) in your code, then your package will be marked as "requiring feature X", and you won't be able to install the package on an organization that does not have that feature enabled.