You need to sign in to do that
Don't have an account?
Ankit Sharma 183
i will create a community and domain. after create apex class page of register page it will not register and it will return null value
/**
* An apex class that creates a portal user
*/
public class SiteRegisterController {
// PORTAL_ACCOUNT_ID is the account on which the contact will be created on and then enabled as a portal user.
// you need to add the account owner into the role hierarchy before this will work - please see Customer Portal Setup help for more information.
public SiteRegisterController () {
}
public String firstname {set;get;}
public String lastname {set;get;}
public String username {get; set;}
public String email {get; set;}
public String userType {set;get;}
public String password {get; set; }
public String confirmPassword {get; set; }
public String communityNickname {set;get; }
public string salesteamprofile = '00e6F000002KX0M';
public string operationteamprofile = '00e6F000002KX0g';
public string accountteamprofile = '00e6F000002KX0R';
private boolean isValidPassword() {
return password == confirmPassword;
}
public PageReference registerUser() {
// it's okay if password is null - we'll send the user a random password in that case
if (!isValidPassword()) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
ApexPages.addMessage(msg);
return null;
}
User u = new User();
u.FirstName = firstname;
u.LastName = lastname;
u.Username = email;
u.Email=email;
u.UserType__c=userType;
if(email.length()> 30)
{
u.CommunityNickname=email.substring(0,30);
}
else
{
u.CommunityNickname=email;
}
if(usertype=='SalesTeam')
{
u.ProfileId=salesteamprofile;
}
else if(userType == 'AccountTeam')
{
U.ProfileId = accountTeamprofile;
}
else
{
u.ProfileId = operationteamprofile;
}
// lastName is a required field on user, but if it isn't specified, we'll default it to the username
String userId = Site.createPortalUser(u, '0016F00002SeAmS' , password);
if (userId != null) {
if (password != null && password.length() > 1) {
String returl = '';
if(usertype == '')
{
returl ='/salesteam';
}
else if(usertype == 'operationUser')
{
returl ='/operationteam';
}
else
{
returl ='/accountteam';
}
return Site.login(username, password, returl);
}
else {
PageReference page = System.Page.SiteRegisterConfirm;
page.setRedirect(true);
return page;
}
}
return null;
}
}
* An apex class that creates a portal user
*/
public class SiteRegisterController {
// PORTAL_ACCOUNT_ID is the account on which the contact will be created on and then enabled as a portal user.
// you need to add the account owner into the role hierarchy before this will work - please see Customer Portal Setup help for more information.
public SiteRegisterController () {
}
public String firstname {set;get;}
public String lastname {set;get;}
public String username {get; set;}
public String email {get; set;}
public String userType {set;get;}
public String password {get; set; }
public String confirmPassword {get; set; }
public String communityNickname {set;get; }
public string salesteamprofile = '00e6F000002KX0M';
public string operationteamprofile = '00e6F000002KX0g';
public string accountteamprofile = '00e6F000002KX0R';
private boolean isValidPassword() {
return password == confirmPassword;
}
public PageReference registerUser() {
// it's okay if password is null - we'll send the user a random password in that case
if (!isValidPassword()) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
ApexPages.addMessage(msg);
return null;
}
User u = new User();
u.FirstName = firstname;
u.LastName = lastname;
u.Username = email;
u.Email=email;
u.UserType__c=userType;
if(email.length()> 30)
{
u.CommunityNickname=email.substring(0,30);
}
else
{
u.CommunityNickname=email;
}
if(usertype=='SalesTeam')
{
u.ProfileId=salesteamprofile;
}
else if(userType == 'AccountTeam')
{
U.ProfileId = accountTeamprofile;
}
else
{
u.ProfileId = operationteamprofile;
}
// lastName is a required field on user, but if it isn't specified, we'll default it to the username
String userId = Site.createPortalUser(u, '0016F00002SeAmS' , password);
if (userId != null) {
if (password != null && password.length() > 1) {
String returl = '';
if(usertype == '')
{
returl ='/salesteam';
}
else if(usertype == 'operationUser')
{
returl ='/operationteam';
}
else
{
returl ='/accountteam';
}
return Site.login(username, password, returl);
}
else {
PageReference page = System.Page.SiteRegisterConfirm;
page.setRedirect(true);
return page;
}
}
return null;
}
}