I am creating a new community user via an apex controller using
Site.createExternalUser(user, accountId, password, sendEmailConfirmation)
method.
The community user is getting created ok but I am not getting a welcome email sent out from Salesforce, even though the sendEmailConfirmation
parameter is set to true
.
If I manually click on Enable Customer User
from the Person Account instead then I get an email sent so it isn't related to email deliverability.
public static void createPortalUser(Id accountId) {
Account person = getAccount(accountId);
String firstName = 'unknown';
String lastName = 'name';
if (person.FirstName != null) {
firstName = person.FirstName;
}
if (person.LastName != null) {
lastName = person.LastName;
}
string nickname = firstName.substring(0, 1) + lastName;
User u = new user();
u.FirstName = person.FirstName;
u.LastName = person.LastName;
u.Email = person.PersonEmail;
u.Alias = nickname.abbreviate(8); // only 8 characters
u.Username = person.PersonEmail;
u.CommunityNickname = nickname.abbreviate(40);
u.LocaleSidKey = 'en_GB';
u.TimeZoneSidKey = 'Europe/London';
u.profileId = getCommunityLoginProfile('Portal Login User');
u.LanguageLocaleKey = 'en_US';
u.EmailEncodingKey = 'UTF-8';
u.ContactId = person.PersonContactId;
u.IsActive = true;
String userId = Site.createExternalUser(u, accountId, null, true);
}
Site.createExternalUser(u, accountId, null)
does work, so try that. sendEmailConfirmation is redundant anyway since your password parameter is null and that should force the email to be sent.Site.createExternalUser(u, accountId, null)
still doesn't send an email out unfortunately