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
Michael DsozaMichael Dsoza 

Test Data for User Territory Hierarchy


How can we create test data for User Territory Hierarchy. Since UserTerritory object does not allow DML operation and we can't assign Territory to the User. Do we need to create data (User, Territory & UserTerriotry) manually before running test class ?? 


sharathchandra thukkanisharathchandra thukkani
use @istest(seeAllData=true) anotation in your test class and query on the UserTerritory object, before deploying in production you need to enable territory management in your org.
Michael DsozaMichael Dsoza
Hi sharathchandra,

Thanks for your reply.

Territory Management is enabled but how can we insert data in UserTerritory as DML operations are not allowed on UserTerritory.
Also, Using seeAllData = true is not good practice. So is their alternative approach to insert records in UserTerriotry object OR we need to create required User Territory Hierarchy before running test classes ??