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 theirthey'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