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
ravi1234.ax1565ravi1234.ax1565 

trigger

hello group ,

 

 

          can we create a user using trigger, if possible how ,

 

              if not why?

 

                            help full to me if any code references 

      

   thanks for giving reply in advance

 

 

                thanks and regerds

           

Best Answer chosen by Admin (Salesforce Developers) 
Vinit_KumarVinit_Kumar

Ravi,

 

You can store value which are required to create a user record on a custom object and then on the on insertion of record of that custom object,you can populate the fields for user record and create a user record.

 

Basically,you can write a Trigger on custom object and populate the fields for user record and then can insert the record.You can try below sample code for your reference which you can use in your Trigger:-

 

User u2 = new User(username='vkumar@chatter.com', firstname='Vinit',
lastname='Kumar', email='vkumar@salesforce.com',communityNickname = 'vkumar_sfdc',
alias = 'vkumar123', profileid = '00e90000000nyqv', emailencodingkey='UTF-8',
languagelocalekey='en_US', localesidkey='en_US', timezonesidkey='America/Los_Angeles');
 
insert u2;

All Answers

kriskkrisk

There is no ability to create a user via a Trigger functionality. 

 

Triggers are invoked upon Inserting or Updating database objects.

 

There is a way to create users using SOAP and REST API by assigning a role and profile if you are looking for an automatic way of creating User.

Vinit_KumarVinit_Kumar

Ravi,

 

You can store value which are required to create a user record on a custom object and then on the on insertion of record of that custom object,you can populate the fields for user record and create a user record.

 

Basically,you can write a Trigger on custom object and populate the fields for user record and then can insert the record.You can try below sample code for your reference which you can use in your Trigger:-

 

User u2 = new User(username='vkumar@chatter.com', firstname='Vinit',
lastname='Kumar', email='vkumar@salesforce.com',communityNickname = 'vkumar_sfdc',
alias = 'vkumar123', profileid = '00e90000000nyqv', emailencodingkey='UTF-8',
languagelocalekey='en_US', localesidkey='en_US', timezonesidkey='America/Los_Angeles');
 
insert u2;
This was selected as the best answer
ravi1234.ax1565ravi1234.ax1565
thanks for giving reply vinith

thanks and regards