-1

What is the best practice of creating community users? Is it by using Site.createExternalUser api or directly inserting user object?

1
  • Site.createExternalUser has a myriad of issues, it's only good in very few happy path scenarios.
    – identigral
    Sep 22 at 15:41

1 Answer 1

0

Creating a user and a contact in the same transaction is not allowed. You end up with a MIXED_DML exception. Workarounds exist, but are not ideal. If you use Site.createExternalUser, it will create the user and contact (if necessary) all in one step. In addition, you can also set their default password (or any supplied password) at once, which can also be used with Site.validatePassword to make sure the passwords match and match the org's password policies. In other words, you should not be using a standard DML operation to create external community users. The Site method is the recommended approach.

2
  • So what if I want to relate the community user to an existing contact. And the matching contact is identified using a custom text field . In that scenario whether i can use Site.CreateExternalUser? Sep 22 at 6:48
  • @LoneWolf777 The createExternalUser method matches strictly by email, not a custom field. If you already have the custom data you're looking for, it should be easy to get the email for the contact from there.
    – sfdcfox
    Sep 22 at 14:31

You must log in to answer this question.

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