I'm trying to write an Apex web service that can create a customer portal user. After creating the user, there is a separate step which does a password reset for the user and sends them an email.
The problem I'm running into is that Salesforce is automatically sending the user an email when the Contact and User are created. I want to prevent this so I can send the email later after setting their password.
I've tried the code below, which sounds like it should work according to the docs.
Database.DMLOptions dlo = new Database.DMLOptions(); dlo.EmailHeader.triggerUserEmail = false; dlo.EmailHeader.triggerAutoResponseEmail = false; dlo.EmailHeader.triggerOtherEmail = false; ... contact.setOptions(dlo); Database.insert(contact, dlo); ... user.setOptions(dlo); Database.insert(user, dlo);
Unfortunately, each time I create a user with the webservice I'm still receiving an email from Salesforce, despite setting these flags on DMLOptions...
Does anybody know of a solution which will prevent this from happening?
Edit: I also tried with Site.createPortalUser(user, acctId, null, false). This didn't work for the following reason:
System.TypeException: That operation is only allowed from within an active site.