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
BugudeBugude 

Upsert User - DML not allowed on User

I am trying to create a user using Apex class for which I have written the following code.

<Previous Code>
User user = new User();

user.FirstName = String.valueOf(usr.FirstName);
user.LastName = String.valueOf(usr.LastName);
user.Username = String.valueOf(usr.UserName);
.
.
.
<set the values for all the required field>
Upsert user;
<Following Code>

When i am trying to save the class, I am facing the following error.

"DML not allowed on User".

Please suggest.
cARL scARL s

You is prolly hittin some license limit issues cuz u creatin' users in a dev org.  Try settin the user IsActive flag to false in ur tests and that mite fix it.

mohimohi

did you try :

upser user <UniqueIdentifier OR ExternalID field>.

lik if my externalid filed is external__c the syntax upsert user external__c ;

BugudeBugude

Mohi,

 

I tried the external id option also but still got the same error.

 

I tried Insert user and Update user, surprisingly they are working fine but upsert user is not working.

 

Regards,

Lakshman