Is a mechanism like Site.createPortalUser available where the Contact already exists?

As I understand the Site.createPortalUser method, it results in a new Contact object and User object being created.

Is it possible to instead have the Contact pre-existing, and to only add the User object (and still have the standard new user email process execute) by any means?

The use case is a customer portal where only a small proportion of customers ever choose to register and the registration process is based on the Contact.Email field of pre-existing Contacts. (So the registration happy path would be for a single pre-existing Contact to match the email address. Then a means would be needed for the controller to specify that pre-existing Contact when the portal User is created.)

Answer

I went ahead and did some testing to get empirical confirmation of the last comment in the post Contact creation in Site.createPortalUser using the CommunitiesSelfRegController. (I started out trying to do this from the developer console but you get told “System.TypeException: That operation is only allowed from within an active site”.) Note that the CommunitiesSelfRegController sets the email address for the User but does not set the contactId for the User.

The results confirm the post:

  • When you enter an email address for the new user that is not already present in one of the Account’s Contacts a new Contact is created
  • When you enter an email address for the new user that is present in exactly one of the Account’s Contacts the existing Contact is used – this is the behavior I want
  • When you enter an email address for the new user that is present in more than one of the Account’s Contacts a new Contact is created

And some code could be added to CommunitiesSelfRegController to handle the third case differently.

Attribution
Source : Link , Question Author : Keith C , Answer Author : Keith C

Leave a Comment