• jessiereed
  • NEWBIE
  • 5 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 1
    Replies
I can't get the autocreatedreghandler to work for single sign-on (SSO) into our community. I want users to be able to register using their google accounts.  This is the Apex Class I'm using, which was autogenerated by Salesforce when I set up the Auth provider. The Account "Self-Registered Community Users" exists in my environment, and the Profile "Customer Community Login User" exists. Any help is appreciated!
 
//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 AutocreatedRegHandler1437665762204 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
   // User u = [Select Id , username from User where email =: data.email];
     //   return u;
  //}
  if(data.attributeMap.containsKey('sfdc_networkid')) {
    //We have a community id, so create a user with community access
    //TODO: Get an actual account
    Account a = [SELECT Id FROM account WHERE name='Self-Registered Community Users'];
    Contact c = new Contact();
    c.accountId = a.Id;
    c.email = data.email;
    c.firstName = data.firstName;
    c.lastName = data.lastName;
    insert(c);

    //TODO: Customize the username and profile. 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.
    User u = new User();
    Profile p = [SELECT Id FROM profile WHERE name='Customer Community Login User'];
    u.username = data.username;
    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;
    u.contactId = c.Id;
    return u;
  } else {
    //This is not a community, so create a regular standard 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 + '@SRCU.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);
}
}

 
I want to change the image that appears by default (user.smallphotourl) on a user's profile in Communities. Right now its a smiley face, but I want to change it to brand the whole community. We have Enterprise and are using the Napili template. Where is this setting?

I've attached a photo to show what I mean.User-added image
I want to change the image that appears by default (user.smallphotourl) on a user's profile in Communities. Right now its a smiley face, but I want to change it to brand the whole community. We have Enterprise and are using the Napili template. Where is this setting?

I've attached a photo to show what I mean.User-added image

Has anyone embedded video in the new Knowledge Base app?  I found an idea related to it, so I'm guessing it's not possible through the delivered article managment UI where the end user could easily embed the video themselves.  I'm sure it's possible with VF, but haven't seen anyone else who has done it.

 

Here's the link to the idea:  Embed Video in Knowledge Base

I would like to ask you about Auth Provider:

I have a Registration Handler in a DE org linked to my Auth provider, it is working correctly and allowing the external users to register.

Now I decided to pass it to my sandbox, I created a new Auth provider, with the new reg handler. The code is the same.

The url is something like: https://test.salesforce.com/services/auth/sso/xxxxxxxxx/myAuthProvider

(in the dev org was something like https://login.salesforce.com/services/auth/sso/xxxxxxxxx/myAuthProvider)

Checking if there is a user for the email and if not create a new one with Community User profile ( High Volume Customer Portal - the org has licenses for it) .

-If there is no user that match the email a new one is created.

-If there is that is returned.

IN both cases the registration is not working in the Sandbox

However if I go to my DE org where I have the same structure created ( Auth provider + reg handler) it is working.

Code , Profiles , licenses are the same.

Here it is a example of the code ( when I say sample is because I reduce it to the simple case , no validations or checks are on it at the moment)
global class RegHandler implements Auth.RegistrationHandler{

global boolean canCreateUser(Auth.UserData data) {
    return false;
}

global User createUser(Id portalId, Auth.UserData data){


    String profileName = 'Community User';

    List<Profile> profiles = [SELECT Id, Name, UserType FROM Profile WHERE Name = :profileName];

    Profile profile = profiles.isEmpty() ? null : profiles[0];

    if(profile==null)
        throw new RegHandlerException('Could not find the profile');

    List<User> users = [SELECT Id,Email,Username,FirstName,LastName,Alias,CommunityNickname,ProfileId,
        ContactId,LocaleSidKey,LanguageLocaleKey,TimeZoneSidKey,EmailEncodingKey FROM User WHERE  Email = :data.Email and IsActive=true]; // Standard: to exclude Guest user (etc?)Profile.UserType = 'CspLitePortal' and Name='Carolina Ruiz Medina'];// 
    User user = users.isEmpty() ? null : users[0];

    if(user==null)
    {
        List<String> emailComponents = data.email.split('@');
        String nickname = data.attributeMap.get('display_name');
        Contact ct = new Contact(
            LastName = data.LastName,
            AccountId =  '00119000002uozp');
        upsert ct;

        user = new User(
            Email = data.email,
            Username = emailComponents[0] + '@ffcommunity.com',
            Alias = emailComponents[0].left(8),
            CommunityNickname = nickname,
            ProfileId = profile.Id,
            FirstName = data.firstName,
            LastName = data.lastName,
            LocaleSidKey = data.locale,
            LanguageLocaleKey = data.attributeMap.get('language'),
            TimeZoneSidKey = 'Europe/London',
            EmailEncodingKey  = 'ISO-8859-1',
            contactId = ct.Id

        );

    }
    return user;
}

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);
}



class RegHandlerException extends Exception {}
}


I know that the orgs that will connect with the sandbox will be also in test.salesforce.com server. ( like before the orgs connecting to my DE org where the Auth provider is working were DE orgs too)

Then in summary when I try to registre/log using auth provider URL is alwayws giving me the error:AuthorizationError?ErrorCode=NO_ACCESS&ErrorDescription=User+was+a+portal+user

Any help would be much appreciated. 

( The question is also here: http://salesforce.stackexchange.com/questions/48326/auth-provider-authorizationerrorerrorcode-no-accesserrordescription-userwas)