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
sai.sfsai.sf 

User is not receiving an email

Hi All,

 

  I am able to create a new user through apex but the user is not receiving an password confirmation email.Any thoughts?

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
TejTej

Try The below code, works for me.

 

 

Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = true;
dlo.EmailHeader.triggerAutoResponseEmail= true;

 

user.setOptions(dlo);
insert user;

All Answers

JBabuJBabu

Hi,

 

Recheck the email id mentioned which you have used while creating.

 

Thanks,

Babu.

sai.sfsai.sf

i have to manually check this checkbox........ Generate new password and notify user immediately ....... for the user to receive an email.I want to automate it.

TejTej

Try The below code, works for me.

 

 

Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = true;
dlo.EmailHeader.triggerAutoResponseEmail= true;

 

user.setOptions(dlo);
insert user;

This was selected as the best answer
sai.sfsai.sf

Thanks Tej.

praveen murugesanpraveen murugesan
Its worked