You need to sign in to do that
Don't have an account?
RoleId while creating Person Account and User as owner of that Person account through Apex.
Hi,
In the belowcode I am not getting how to input the RoleId of the User for which I am creating Person Account . In our customer Portal we have assigned Default role of user to Empty. But the above future call is throwing an error that 'Account Owner should have some role' and when I am passing some role to this 'UserRoleId' field it throwing again an error '
High Volume Portal Users cannot have a user role' can any one suggest what should I pass as UserRoleId in order to make my Future call working and the user can be cretesd with its personal account.
'
public with sharing class CustomUserSiteRegister{
public string fNAme{get; set;}
public String lastName{get; set;}
public String email{get; set;}
public String confirmEmail{get; set;}
public string country{get; set;}
public string state{get; set;}
public string city{get; set;}
public String communityNickname{get; set;}
public pagereference makeUserPersonAcc(){
recordType recType1 = [SELECT Name, SobjectType,IsPersonType FROM RecordType WHERE SobjectType='Account' AND developername = 'Person_Account' AND IsPersonType = true ];
Account personAcc= new Account();
personAcc.recordtype = recType1 ;
personAcc.firstName = fName;
personAcc.lastName = lastName;
personAcc.PersonEmail= email;
personAcc.BillingCountry = country;
personAcc.BillingState = state;
personAcc.BillingCity = city;
insert personAcc;
system.debug('this is peronAcc'+personAcc);
UserRole usrRole = [Select PortalAccountOwnerId,Name, PortalAccountId From UserRole limit 1];
system.debug('thi is usrRole'+ usrRole);
Profile p = [select id ,Name from profile where UserLicense.Name like '%Authenticated Website%' limit 1];
Profile p1 = [select id ,Name from profile where Name = 'Authenticated User'];
system.debug('this is profileName'+p1.Name);
Account getCon = [select id , PersonContactId from account where id =: personAcc.id];
system.debug('this is getCon'+personAcc.PersonContactId );
createUser(getCon.PersonContactId , personAcc.PersonEmail, personAcc.firstName, personAcc.lastName, Email ,(string)p1.id );
return null;}
// Setup nonSetup objects problem , so used @future.
@future static void createUser(id con, String email, String firstName, String lastName, String userName, String profileId ) {
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.EmailHeader.triggerUserEmail = true;
system.Debug('I am here'+con);
system.Debug('I am here');
system.Debug('I am here'+email);
User u = new User(alias = 'standt', email=email,
emailencodingkey='UTF-8', lastname=lastname, languagelocalekey='en_US',
localesidkey='en_US', profileid = profileId, contactId=con,
timezonesidkey='America/Los_Angeles', username=username , UserRoleId = '');
u.setOptions(dmo);
insert u;
}
I think the issue is the owner of the person account needs to have a role. Also, beware there is a limit to how many portal enabled person accounts any single user can be owner of. That limit is 1,000.