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

Create User via Apex

Hello Community!


I'm encountering the problem that I need to create on every org with my app two dummy users as a placeholder. Since I got a first-start-apex-controller I would like to integrate the creation of User in it. But I can't use the User-Object because of read-only-permission, as Eclipse says to me. 

So does anyone know how to do this?


Thanks a lot and Best Regards






You can create users via apex. There are certain object which doesnot support DML operation and user object isn't one of them. You can check "sObjects That Do Not Support DML Operations" for more details.


Only thing to be considered is that you cannot insert setup and non set up objects toggether.





Hello Ahmed!

Thanks for your answer! 

I thought there might be a problem, that I didn't set all the required fields for creating a new user and that's why it gave me the error msg.

I'll give it a try in near future and will post my solution later on!






Hi !! Can any one tell me how can I create a user(chatter only) with apex code in my web site and , I don't know if Guest profile permissions allow that ?