0

I am using Google Open ID Connect to link up with Communities , I have configured everything as in the documentation , but I am getting the below error in the url: "Cannot create Portal user without contact"

So anyone please help me , my google registration handler is as follows :

  global class GoogleOpenIDConnect implements Auth.RegistrationHandler{
    global User createUser(Id portalId, Auth.UserData data){
    User u = new User();
    Profile p = [SELECT Id FROM profile WHERE id='00e240000011E3g'];
    u.username = data.email;
    u.email = data.email;
    u.lastName = data.lastName;
    u.firstName = data.firstName;
    u.timeZoneSidKey = 'Europe/Paris';
    u.localesidkey = 'en_GB';
    u.emailEncodingKey = 'UTF-8';
    u.languagelocalekey = 'en_US';
    String alias = data.firstName + data.lastName;
    if(alias.length() > 8) {
    alias = alias.substring(0, 8);
   }
    u.alias = alias;
    u.profileId = p.Id;
    return u;
    }


 global void updateUser(Id userId, Id portalId, Auth.UserData data){
   User u = new User(id=userId);
   u.email = data.email;
   u.lastName = data.lastName;
   u.firstName = data.firstName;
  update(u);
 }

}

1

Community Users needs a Contact (linked to a valid Contact). So you have to do something like in the createUser method:

Account acc = new Account(Name = data.lastname);
insert acc;//you can also query an account
Contact cnt = new Contact(FirstName = data.firstname, LastName = data.lastname, AccountId = acc.Id);
insert cnt;//you can create a PersonAccount instead
u.contactid = cnt.Id;
return u;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.