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
GriffindorGriffindor 

DML not allowed on userterritory

Hi,

 

I have a vf controller from where I need to insert records into the userterritory table. However, I am receiving a compilation error which is as follows:-

Compile Error: DML not allowed on UserTerritory 
Is there any way to insert records into the UserTerritory table?
I have tried using an action function to call the controller method, but the compiler does not allow me to save the controller with the insert or the Database insert command on user territory table.
 
Any help is much appreciated.
 
Thanks in advance!!
chris.noechris.noe

DML operations are not permitted on the UserTerritory object.  See "sObjects That Do Not Support DML Operations" in the Apex developer guide.

GriffindorGriffindor

Hi Chris,

 

Thanks for your reply. Is there any other way other than apex using which we can do a DML on user territory? We can insert records into user territory using api calls I believe like in the data loader. I need to customize this through code just like the way territory management works for users in the UI.

bbrantly1bbrantly1

Looks like you can use the SOAP or REST API to insert a userterritory record. You can see this in action if you use the force.com workbench https://workbench.developerforce.com