• Alexis Scott 16
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
Hello! 

I am setting up Google SSO for Salesforce and I have this autoreghandler that I need a test class for. I'm not really a developer so I was wondering if someone could help me? I just need the code coverage so I can upload other things into production. 
 
//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 AutocreatedRegHandler1537799224416 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;
	}
	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='Acme'];
		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 Portal User'];
		u.username = data.username + '@acmecorp.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;
		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 + '@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);
}
}

I have this test class but it's only covering like 9%
 
@isTest
//https://help.salesforce.com/articleView?id=sso_authentication_providers.htm
private class StandardUserRegistrationHandlerTest3 {
static testMethod void testCreateAndUpdateUser() {
    AutocreatedRegHandler1537799224416 handler = new AutocreatedRegHandler1537799224416();
    // UserData class: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Auth_UserData.htm
    // https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_auth_plugin.htm
    Auth.UserData sampleData = new Auth.UserData('testId', 'testFirst', 'testLast',
        'testFirst testLast', 'testuser@example.org', null, 'testuserlong', 'en_US', 'facebook',
        null, new Map<String, String>{'language' => 'en_US','site' => 'test'});
    Id portalId = null;
    User u = handler.createUser(portalId, sampleData);
    //System.assertEquals('testuserlong@myorg.com', u.userName);
    //System.assertEquals(true,sampleData.attributeMap.containsKey('language'));
    //System.debug(sampleData.attributeMap);
    
    System.assertEquals('testuser@example.org', u.email);
    System.assertEquals('testLast', u.lastName);
    System.assertEquals('testFirst', u.firstName);
    System.assertEquals('testuser', u.alias);
    insert(u);
    String uid = u.id;
    
    sampleData = new Auth.UserData('testNewId', 'testNewFirst', 'testNewLast',
        'testNewFirst testNewLast', 'testnewuser@example.org', null, 'testnewuserlong', 'en_US', 'facebook',
        null, new Map<String, String>{'language' => 'en_US'});
    handler.updateUser(uid, null, sampleData);
    
    
    User updatedUser = [SELECT userName, email, firstName, lastName, alias FROM user WHERE id=:uid];
    //System.assertEquals('testnewuserlong@acmecorp.com', updatedUser.userName);
    System.assertEquals('testnewuser@example.org', updatedUser.email);
    System.assertEquals('testNewLast', updatedUser.lastName);
    System.assertEquals('testNewFirst', updatedUser.firstName);
    //System.assertEquals('testnewu', updatedUser.alias);
}
}

 
Hello, 

We deployed My Domain this morning and some of our users are having issues logging in. When they try to login from both login.salesforce.com and our custom domain they are redirected back to the login screen after they enter their credentials and press submit. On our admin side, it shows their log ins as successful, but they cannot actually get into the instance. 

We have tried clearing caches, disabling extensions, etc. but nothing has allowed them to log in. 

Has any one ever encountered this problem? Do you know a solution? 
Hello, 

I am setting up Files Connect for google drive and I keep getting the following error: 

The redirect URI in the request does not match the ones authorized for the OAuth client. 

I have checked multiple times and the callback uri I entered is the correct one. Is there a way to fix this? I do not get why I am getting this error since I entered the callback uri in google correctly. 

Does it take time for this to work properly? 
But when I try to set the flow variables in process builder I am getting this error: 

Data Input Name: data value too large: myInvokeFlowRecordLookup_myWaitEvent_myWait_myRule_1_event_0_SA1oppsProductsOriginal (max length=80) 

Does anyone know how to fix this? 
So I am trying to integrate Google Drive into my SF org, and I have followed all of the steps correctly, but when we try to validate and sync the drive to SF, we get this response: 

No_Openid_Response: Bad response. Please contact your administrator. 

Am I missing something? Is there something else I need to do that is not listed in the documentation? 

Thank you! 
Hello, 

I am setting up Files Connect for google drive and I keep getting the following error: 

The redirect URI in the request does not match the ones authorized for the OAuth client. 

I have checked multiple times and the callback uri I entered is the correct one. Is there a way to fix this? I do not get why I am getting this error since I entered the callback uri in google correctly. 

Does it take time for this to work properly?