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
praveen murugesanpraveen murugesan 

User is not receiving an email in one org but not receiving in another org

Hi All,

 I am able to create a new user through apex code but the user is not receiving an password confirmation email in one org. But I have used same code in another org in that user is receiving mail perfectly.   Any suggestions??

I have used this code 

Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = true;
dmlo.EmailHeader.triggerAutoResponseEmail= true;
user.setOptions(dmlo);
insert user;


Thanks.
Sonam_SFDCSonam_SFDC
Is that org sending any email out? Askign this questions as there is a setting under Setup > Email Administration > Deliverability which when setup as No Access restricts all emails being sent out from the ORG:

http://help.salesforce.com/apex/HTViewHelpDoc?id=emailadmin_deliverability.htm

Please check.. 


Vinita_SFDCVinita_SFDC
Hi,

Please check if the email is being sent or not from the code, for this check debug logs and email logs from setup for this user.

Setup|Administration setup|Monitoring|Debug logs/Email log files

Also verify the email settings from the org where it is working.
praveen murugesanpraveen murugesan
Sonam,

Thanks for your time I have checked the access level is All email only.
praveen murugesanpraveen murugesan
Vinita,

I have checked in both debug log and email log and I couldn't find any error. 

And if i checks Generate password and notify to user check box in user detail page(user which i have created using apex) email is sending properly.

While creating new user using apex only it is not sending.
Vinita_SFDCVinita_SFDC
Hi Praveen,

Can you test if this works:

User l = new User(alias = 'newu', email=email,
emailencodingkey='UTF-8', lastname=lastname, languagelocalekey ='en_US',
localesidkey='en_US', profileid = profileId, contactId=contactId,
timezonesidkey='America/Los_Angeles', username=username);

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
dmo.EmailHeader.triggerUserEmail = true;
Database.insert (l, dmo);
praveen murugesanpraveen murugesan
Vinita,

It is not working. I am inserting only user record. I think no need to use assignmentRuleHeader. This are the data i am using to create a record 

User:{Phone=34543432, TimeZoneSidKey=Europe/London, UserPermissionsSFContentUser=true, LanguageLocaleKey=en_US, UserPreferencesContentEmailAsAndWhen=true, ProfileId=00eb0000000ct9oAAA, LocaleSidKey=en_GB, LastName=Saravanan, UserPreferencesContentNoEmail=true, EmailEncodingKey=ISO-8859-1, Email=pra--nm@---.com, Alias=TeS, Username=pra--ms@----.com, FirstName=Test, MobilePhone=898888665}