• SFDEV Thor
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Sr. Salesforce Frontend Developer


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
We have a Lightning Community and enabled Self Registration.
The issue is weird. It takes approx 20-25 seconds for the very first User registration of the day and all user registrations onwards take only 2.5-3 seconds. We are facing this problem on normal sandbox as well as on partial sandbox also.
Code snippet is as below:
 
public void registerUser(String newUserJson) {
	// This is the input, received from an Lightning Component
	Contact userContact = (Contact)JSON.deserialize(newUserJson, Contact.class);
	
	// This Account has Owner which has role - No issue here
	Account userAccount = [SELECT Id FROM Account WHERE Name = 'Individual' LIMIT 1];	
	
	Profile userProfile = [SELECT Id FROM Profile WHERE Name = 'ABC Community User' LIMIT 1];

	// Setup User data
	User newUser = new User();
	newUser.UserName = generateUniqeUserName(userContact.Email);
	newUser.Email = userContact.Email;
	newUser.FirstName = userContact.FirstName;
	newUser.LastName = userContact.LastName;
	newUser.ProfileId = userProfile.Id;

	// If using site to host the community the user should not hit s1 after logging in from mobile.
	String networkId = Network.getNetworkId();
	if (networkId != null && siteAsContainerEnabled(Network.getLoginUrl(networkId))) {
		newUser.UserPreferencesHideS1BrowserUI = true;
	}

	// Compute dynamic nickname for user
	String nickname = ((userContact.FirstName != null && userContact.FirstName.length() > 0) ? userContact.FirstName.substring(0, 1) : '' ) + userContact.LastName.substring(0, 1);
	nickname += String.valueOf(Crypto.getRandomInteger()).substring(1, 7);
	newUser.CommunityNickname = nickname;

	// First Create Contact	
	userContact.AccountId = userAccount.Id;
	INSERT userContact;
		
	// Create User
	newUser.ContactId = userContact.Id;
	String userId = Site.createPortalUser(newUser, userAccount.Id, password, true);
}

public static boolean siteAsContainerEnabled(String communityUrl) {
	Auth.AuthConfiguration authConfig = new Auth.AuthConfiguration(communityUrl, '');
	return authConfig.isCommunityUsingSiteAsContainer();
}
	
public static String generateUniqeUserName(String email) {        
	return email + ((isSandbox() == true) ? '.abc.sandbox' : '.abc');
}

public static Boolean isSandbox() {
	return [SELECT Id, Name, OrganizationType, NamespacePrefix, InstanceName, IsSandbox FROM Organization].IsSandbox;
}

Please advise what might be taking so long time for simple User registration.

Note: We don't have any other failure in code or complete process, its all about long execution time for only first user registration of the day.
Thanks.
We have a Lightning Community and enabled Self Registration.
The issue is weird. It takes approx 20-25 seconds for the very first User registration of the day and all user registrations onwards take only 2.5-3 seconds. We are facing this problem on normal sandbox as well as on partial sandbox also.
Code snippet is as below:
 
public void registerUser(String newUserJson) {
	// This is the input, received from an Lightning Component
	Contact userContact = (Contact)JSON.deserialize(newUserJson, Contact.class);
	
	// This Account has Owner which has role - No issue here
	Account userAccount = [SELECT Id FROM Account WHERE Name = 'Individual' LIMIT 1];	
	
	Profile userProfile = [SELECT Id FROM Profile WHERE Name = 'ABC Community User' LIMIT 1];

	// Setup User data
	User newUser = new User();
	newUser.UserName = generateUniqeUserName(userContact.Email);
	newUser.Email = userContact.Email;
	newUser.FirstName = userContact.FirstName;
	newUser.LastName = userContact.LastName;
	newUser.ProfileId = userProfile.Id;

	// If using site to host the community the user should not hit s1 after logging in from mobile.
	String networkId = Network.getNetworkId();
	if (networkId != null && siteAsContainerEnabled(Network.getLoginUrl(networkId))) {
		newUser.UserPreferencesHideS1BrowserUI = true;
	}

	// Compute dynamic nickname for user
	String nickname = ((userContact.FirstName != null && userContact.FirstName.length() > 0) ? userContact.FirstName.substring(0, 1) : '' ) + userContact.LastName.substring(0, 1);
	nickname += String.valueOf(Crypto.getRandomInteger()).substring(1, 7);
	newUser.CommunityNickname = nickname;

	// First Create Contact	
	userContact.AccountId = userAccount.Id;
	INSERT userContact;
		
	// Create User
	newUser.ContactId = userContact.Id;
	String userId = Site.createPortalUser(newUser, userAccount.Id, password, true);
}

public static boolean siteAsContainerEnabled(String communityUrl) {
	Auth.AuthConfiguration authConfig = new Auth.AuthConfiguration(communityUrl, '');
	return authConfig.isCommunityUsingSiteAsContainer();
}
	
public static String generateUniqeUserName(String email) {        
	return email + ((isSandbox() == true) ? '.abc.sandbox' : '.abc');
}

public static Boolean isSandbox() {
	return [SELECT Id, Name, OrganizationType, NamespacePrefix, InstanceName, IsSandbox FROM Organization].IsSandbox;
}

Please advise what might be taking so long time for simple User registration.

Note: We don't have any other failure in code or complete process, its all about long execution time for only first user registration of the day.
Thanks.
Hello,

I am using Frontdoor.jsp to Log Into Salesforce from one of the the Salesforce Organization(Source) to another Salesforce Organization (Target).

I have created one Connected App in Target Org with web scope.

Connected App

As per the documentation, we can use access_token from an OAuth authentication instead of Session ID.
https://help.salesforce.com/HTViewHelpDoc?id=security_frontdoorjsp.htm&language=en_US

I am unable to redirect to Target Organization with access_token from an OAuth instead of session ID.

targetURL: https://instance.salesforce.com/secur/frontdoor.jsp?sid=access_token&retURL=optional_relative_url_to_open

Thanks!!!