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
Medhanie Habte 37Medhanie Habte 37 

Issues setting up Social Sign-On with Google

Greetings all,

I am setting up social sign on in a developer org to allow internal users to sign on with Google. I've opted to go with the autogenerated method, however, when I attempt to login with my Google account. I encounter a "User Not Found" Error. I have my RegHandlerClass created below. Any steps I should take?

My federation ID matches my email address if that helps.
 
//TODO:This autogenerated class includes the basics for a Registration
//Handler class. You will need to customize it to ensure it meets your needs and
//the data provided by the third party.

global class AutocreatedRegHandler1492450757085 implements Auth.RegistrationHandler{
global boolean canCreateUser(Auth.UserData data) {
  //TODO: Check whether we want to allow creation of a user with this data
  //Set<String> s = new Set<String>{'usernamea', 'usernameb', 'usernamec'};
  //if(s.contains(data.username)) {
    //return true;
  //}
  return false;
}

global User createUser(Id portalId, Auth.UserData data){
  if(!canCreateUser(data)) {
    //Returning null or throwing an exception fails the SSO flow
    return null;
  }
  //The user is authorized, so create their Salesforce user
  User u = new User();
  Profile p = [SELECT Id FROM profile WHERE name='Standard User'];
  //TODO: Customize the username. Also check that the username doesn't already exist and
  //possibly ensure there are enough org licenses to create a user. Must be 80 characters
  //or less.
  u.username = data.username + '@myorg.com';
  u.email = data.email;
  u.lastName = data.lastName;
  u.firstName = data.firstName;
  String alias = data.username;
  //Alias must be 8 characters or less
  if(alias.length() > 8) {
    alias = alias.substring(0, 8);
  }
  u.alias = alias;
  u.languagelocalekey = UserInfo.getLocale();
  u.localesidkey = UserInfo.getLocale();
  u.emailEncodingKey = 'UTF-8';
  u.timeZoneSidKey = 'America/Los_Angeles';
  u.profileId = p.Id;
  return u;
}

global void updateUser(Id userId, Id portalId, Auth.UserData data){
  User u = new User(id=userId);
  //TODO: Customize the username. Must be 80 characters or less.
  //u.username = data.username + '@myorg.com';
  u.email = data.email;
  u.lastName = data.lastName;
  u.firstName = data.firstName;
  //String alias = data.username;
  //Alias must be 8 characters or less
  //if(alias.length() > 8) {
    //alias = alias.substring(0, 8);
  //}
  //u.alias = alias;
  update(u);
}
}