+ Start a Discussion
DTCFDTCF 

CP user creation not sending emails with dmo.EmailHeader.triggerUserEmail = true;

Hello,

 

I cross posted this to Force.com sites, not exactly sure where it belongs. This is highly urgent as I have a deadline for a demo and can't really have a site that doesn't send emails upon user creation/registration.

 

This functionality was working fine, and then it stopped for some reason, I think after I tried editing the standard new user template for Customer Portal (which btw, wasn't getting picked up...does that have to be an additional parameter in the user creation in Apex?)

 

Any reason why this would be the case? Could this be related to a weird dev org limitation? It was working fine with this code inserting a new user:

 

 

	dmo.EmailHeader.triggerUserEmail = true;
		
    	User u = 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);
        
        u.setOptions(dmo);
        insert u;

 

 

Now, the user is created correctly with the correct email address, but the triggerUserEmail is never sent. If I go into the user and hit the "Reset Password" button, everything works fine as if the user received the email automatically.

 

I'd appreciate if anyone has any thoughts as to why this might be happening. Thanks so much!

Pradeep_NavatarPradeep_Navatar

Try this code :

 

User u = 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 dlo = new Database.DMLOptions();

dlo.EmailHeader.triggerUserEmail= true;                                      

Database.saveresult sr = Database.insert(u1,dlo);

 

This is the tested code to send an email, while creating a Customer Portal user.

 

Hope this helps.