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
Raghavendra ARaghavendra A 

Creating New User via Apex

Hi All,

We are working on requirement where we need to automate the creation of Customer community users. We are taking care of creating a Account, Contact and then creating the User record. The issue that
  • We are facing is that the user can belong to any country. We want to default that country's locale and timezone etc. 
  • How do we handle the duplicate nick name and alias while creating new users in the code?
We want least user interference here. Hence we are automating the entire process. Any suggestions on this is highly appreciated. 

Thanks,
Raghu
Best Answer chosen by Raghavendra A
Balaji BondarBalaji Bondar
Hi Raghavendra,

We are facing is that the user can belong to any country. We want to default that country's locale and timezone etc. 
  1. You can store the country, locale and timezone in one custom setting/custom object.
    Based on users country , you can choose the appropriate details while creation of a user record.
How do we handle the duplicate nick name and alias while creating new users in the code?
  1. Have some custom logic(FirstName 3 letters + Last Name 3 letters + 12 etc).
    After that query on the user object with newly created details such as [select Id from User where nickname ='XXXXXXX' and alias='XXXXXXXXX'].
    If you will find a record have some diff logic in the APEX code.
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.