function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Syed Subhan 9Syed Subhan 9 

Enable portal user for existing contacts during sites self-registration

Hi,
We have deployed the SF community, but when people use the self register link on the site SF creates a contact record and user record on a default account even if the email address matches a current customer.  As you can image managing the default account of contacts is not something I want to deal with.

During the sites self-registration process, I have only come across the ability to create a portal user that creates both a contact and a user synchronously.  I would like to be able to create a portal user using an existing contact.  I tried setting the contact id on the user object before I called createPortalUser, but it still created a new contact.  We are trying to eliminate the possibility of duplicate contacts.

So I am looking for a way to auto match users to their contacts to their user records if the email addresses match.  I understand that this can done with a controller.  I don't do that level of SF work yet, so any help would be great.


Can u post the code in which you were able to enable new users under existing contact. It will help me alot...

 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Syed,

May I suggest you please refer the below link to reference. hope it helps.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
Syed Subhan 9Syed Subhan 9
Hi Rahul, Below is the default self registration controller, I need to modify it to work like creating new users with existing contacts i.e email id.
/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
public with sharing class CommunitiesSelfRegController {

    public String firstName {get; set;}
    public String lastName {get; set;}
    public String email {get; set;}
    public String password {get; set {password = value == null ? value : value.trim(); } }
    public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
    public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
    
    public CommunitiesSelfRegController() {}
    
    private boolean isValidPassword() {
        return password == confirmPassword;
    }

    public PageReference registerUser() {
    
           // it's okay if password is null - we'll send the user a random password in that case
        if (!isValidPassword()) {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
            ApexPages.addMessage(msg);
            return null;
        }    

        String profileId = null; // To be filled in by customer.
        String roleEnum = null; // To be filled in by customer.
       <strong> String accountId = ''; // To be filled in by customer.</strong>
        
        String userName = email;

        User u = new User();
        u.Username = userName;
        u.Email = email;
        u.FirstName = firstName;
        u.LastName = lastName;
        u.CommunityNickname = communityNickname;
    u.ProfileId = profileId;
        
        String userId = Site.createPortalUser(u, accountId, password);
      
        if (userId != null) { 
            if (password != null && password.length() > 1) {
                return Site.login(userName, password, null);
            }
            else {
                PageReference page = System.Page.CommunitiesSelfRegConfirm;
                page.setRedirect(true);
                return page;
            }
        }
        return null;
    }
}

I am looking for the complete code and part of the logic that can be used same in the default self registration controller.

Many thanks,
Syed
David Fincher 2David Fincher 2
Certain individuals who concentrated on writing are contemplating Talos, others ponder Eliminator, however how about we get more serious. The idea isn't new, a hypothetical base was created in the 30th long stretches of the twentieth hundred years. The essential thought came from science and math, however we will attempt to keep it basic. The science part is the essential design which comprises of neuron and perceptron. Information is passed to perceptron and there meant a number. The neuron has the recipe which is applied to the number, and the number is utilized to pursue a choice. For the number related section, a neuron is a capability, which processes the piece of the information, and results are like rating and is gone through layers of neurons. This is an improved on clarification, however it's anything but another innovation, brain networks have been utilized in photograph cameras for a really long time.
Source: https://mobilunity.com/blog/cost-to-hire-machine-learning-developer/