0

I'm creating a Node.JS/JSForce/Express API to create external identity users in SF, but I don't want the user to receive the welcome email for the Experience Site they're enrolled in, although users added via SFDC should. My Typescript code looks like this:

   // Single User record creation
    const userObj : {[key: string]: string}= {};
    // these are the required fields
    userObj['ContactId'] = objRecordData["ContactId"];
    userObj['FirstName'] = objRecordData['FirstName'];
    userObj['LastName'] = objRecordData['LastName'];
    userObj['Alias'] = (objRecordData['FirstName'][0] + objRecordData['LastName']).substring(0,8); // max 8 chars
    userObj['Email'] = objRecordData['Email'];
    userObj['Username'] = objRecordData['Email'];
    userObj['FederationIdentifier'] = objRecordData['Email'];
    userObj['ProfileId'] = await getProfileId("External Identity");
    userObj['EmailEncodingKey'] = 'ISO-8859-1';
    userObj['LanguageLocaleKey'] = 'en_US';
    userObj['LocaleSidKey'] = 'en_GB';
    userObj['TimeZoneSidKey'] = 'Europe/London';
    userObj['IsActive'] = "true";
    await jsforce_conn.sobject("User").create(userObj,
        function(err, ret) {
            if (err || !ret.success) {
                logger.error("create SF User failed: " + JSON.stringify(userObj));
            } else {
                logger.info("Created User record " + ret.id + " for " + userObj['Email']);
                objRecordData['UserId'] = ret.id;
            }
        }
    );

It looks like this is possible via Apex code using the method Site.createPortalUser(user, accountId, password, sendEmailConfirmation) : see https://developer.salesforce.com/forums/?id=9060G000000IA5FQAW

Can it be done? There is a reference to calling Apex code from an LWC, but it's beyond my comprehension currently : https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_call_imperative

2
  • Have you considered turning off the welcome email on Digital Experience? The docs. Commented Jan 25, 2023 at 11:10
  • @Jeferson Chaves If I turn off the "welcome email" then the users added via the SFDC UI won't automatically receive an email (I know colleagues could manually send one, but I'd like to avoid that), so I want to use the apparently existing capability of telling the API not to send it, but I'm not versed in Apex development (yet!)
    – kevstev01
    Commented Jan 25, 2023 at 15:02

2 Answers 2

1

I could think of a workaround. Since JSForce allows to call an apex rest API https://jsforce.github.io/document/#apex-rest, you could write an post method in Apex rest and call it using JSForce.

Apex rest API sample: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm

The post method can use the createExternalUser method https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_sites.htm#apex_System_Site_createExternalUser to control the welcome email.

Regards, Hemant

1
  • Many thanks Hemant, I'll give that a go
    – kevstev01
    Commented Feb 8, 2023 at 9:45
0

According to this documentation https://help.salesforce.com/s/articleView?id=000385107&type=1, email verification cannot be disabled for Community users, the only solution that might work is to disable emails for the entire organisation temporarily https://help.salesforce.com/s/articleView?id=000386740&type=1, but that won't meet my use case

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .