2

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);

}
5
  • Hello, welcome to SFSE. Please take a tour and read How to Ask. It will be much easier to determine what may be the problem if you could provide a code where you create a user. Feb 12, 2020 at 14:54
  • Is this user part of any community?
    – ytiq
    Feb 12, 2020 at 15:46
  • It is a new user that is being created from a Person Account.
    – Kev
    Feb 12, 2020 at 15:49
  • I had a very similar problem where createExternalUser was not sending the email. I solved the problem but unfortunately I didn't post the answer; all I can say is that 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. Feb 12, 2020 at 15:53
  • I just tried Site.createExternalUser(u, accountId, null) still doesn't send an email out unfortunately
    – Kev
    Feb 12, 2020 at 16:04

1 Answer 1

0

We are having a similar problem with using Site.createExternalUser. If "Let guest users see other members of this community" is not checked in the Community Administration preferences, it won't sent the email. I am trying to figure out why. You might check and see if checking this box resolves the issue for you.

2
  • Did you found out the why welcome email was sent when "Let guest users see other members of this community" was checked ?
    – Shamina
    Jan 17 at 8:11
  • No, sorry. It may have something to do with the process that sends the email and that the running user needs to have access to the new user email address? It should be running as a system user, so that doesn't quite make sense...
    – Navigatrix
    Jan 18 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.