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
Subhash Pal 17Subhash Pal 17 

I am free user developer edition

want to add new user using Apex  I have try for it but new user dosnt get display with other user
Mahesh DMahesh D
Please provide us the code which you tried to create the user. Will look into it and help you out.

 
Amit Singh 1Amit Singh 1
Below is an Example
 
Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
  
User usr = new User(LastName = 'LIVESTON',
                     FirstName='JASON',
                     Alias = 'jliv',
                     Email = 'jason.liveston@asdf.com',
                     Username = 'jason.liveston@asdf.com',
                     ProfileId = profileId.id,
                     TimeZoneSidKey = 'GMT',
                     LanguageLocaleKey = 'en_US',
                     EmailEncodingKey = 'UTF-8',
                     LocaleSidKey = 'en_US'
                     );

 
Subhash Pal 17Subhash Pal 17
Thank you very much ,How can I see this user with other pre exsistng users list
Subhash Pal 17Subhash Pal 17
I have this code only problem is this newly added user is not display in user list
Subhash Pal 17Subhash Pal 17
when I run the it shows status successfull but unable to see this user 
Amit Singh 1Amit Singh 1
Setup -> Manage Users -> Users -> You can see list of all users there

OR please check if there is no error while creating the user.
Onesh ReddyOnesh Reddy
Hi Subhash,
The only thing missing in the above code is the INSERT functionality which is used to insert the User.
Please find the below code.
Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
  
User usr = new User(LastName = 'LIVESTON',
                     FirstName='JASON',
                     Alias = 'jliv',
                     Email = 'jason.livston@asdf.com',
                     Username = 'jason.veston@asdf.com',
                     ProfileId = profileId.id,
                     TimeZoneSidKey = 'GMT',
                     LanguageLocaleKey = 'en_US',
                     EmailEncodingKey = 'UTF-8',
                     LocaleSidKey = 'en_US'
                     );
insert usr;

system.debug('User Details ::'+usr);

Let me know if it helps you.

Regards,
Onesh.K
Subhash Pal 17Subhash Pal 17
After insert also it is not shown in the user list
Onesh ReddyOnesh Reddy
Subhash,

Can you try selecting the User list view, If not also try by clicking the letters at bottom right on the reference pic below.
User-added image

Regards,
Onesh.K
Subhash Pal 17Subhash Pal 17
Yes i click all user but it dosnt display I am free developers account is it reason
Mahesh DMahesh D
Hi Subhash,

If you are in Free Developer Edition then you can have only 2 Salesforce Licenses.

I tried the below code in Developer Console:
 
Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
  
User usr = new User(LastName = 'LIVESTON',
                     FirstName='JASON',
                     Alias = 'jliv',
                     Email = 'jason.livston@asdf.com',
                     Username = 'jason.veston@asdf.com',
                     ProfileId = profileId.id,
                     TimeZoneSidKey = 'GMT',
                     LanguageLocaleKey = 'en_US',
                     EmailEncodingKey = 'UTF-8',
                     LocaleSidKey = 'en_US'
                     );
insert usr;

system.debug('User Details ::'+usr);
and got below error:
System.DmlException: Insert failed. First exception on row 0; first error: LICENSE_LIMIT_EXCEEDED, License Limit Exceeded: []

Here you can try 2 things:

(1) Try to de-activate all existing users except the admin user and try to execute the above code in Developer Console. It will create the user and you can able to find it in both debug log and users list.

(2) Change the code as below and it will create the user always:

 
Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Chatter Free User' LIMIT 1];
User usr = new User(LastName = 'LIVESTON',
                     FirstName='JASON',
                     Alias = 'jliv',
                     Email = 'jason.livston@asdf.com',
                     Username = 'jason.vestonOne@asdf.com',
                     ProfileId = profileId.id,
                     TimeZoneSidKey = 'GMT',
                     LanguageLocaleKey = 'en_US',
                     EmailEncodingKey = 'UTF-8',
                     LocaleSidKey = 'en_US'
                     );
insert usr;

system.debug('User Details ::'+usr);
Make sure that the User Name is unique all the time. If you run it in the Developer Console for sure you will get the proper error message.

Note: I tried the above slutions in my Developer Org and they are working as expected.

Please do let me know if it solves your issue.

Regards,
Mahesh