0

I am attempting to use my portal to check a contact's field to specify which profile I would like them to posses. Right now a User can only be created if you have entered a value that matches a particular field on the contact object. If the value passed in exists on a contact record in the system - you must supply the same e-mail address attached to that contact. If all these hold true a user is created using the aforementioned contact.

Here is the code attempting to assign profile Ids before creating the user. (I will clean up the code to not use hardcoded IDs after I know this will work).

User u = new User();
u.Username = username;
u.Email = email;
u.CommunityNickname = username;
u.ContactId = c.Id;
u.LastName = c.LastName;
u.FirstName = c.FirstName;

system.debug('Preparing to assign Profile');
if(c.Value_To_Check__c!= null){
    if(c.Value_To_Check__c== 'Value 1'){
           system.debug('Value 2 found. Assigning profile ID');
           u.ProfileId = '00ei00000017KeH'; 
    }
    else if(c.Value_To_Check__c== 'Value 2'){
           system.debug('Value 2 found. Assigning profile ID');
           u.ProfileId = '00ei00000014qTw';
    }
    else if(c.Value_To_Check__c== 'Value 3'){
           system.debug('Value 3 found. Assigning profile ID');
           u.ProfileId = '00ei00000017Jrq';
    }
    else if(c.Value_To_Check__c== 'Value 4'){
            system.debug('Value 4 found. Assigning profile ID');
            u.ProfileId = '00ei0000001DZOg';
    }
}
String accountId;
if(c.AccountId == null){
    accountId = PORTAL_ACCOUNT_ID;
    system.debug('Using default portal account ID');
}
else{
    accountId = c.AccountId;
    system.debug('Using contacts account Id: ' + c.AccountId); 
}
String userId;
try{
    system.debug('Creating portal user');  
    userId = Site.createPortalUser(u, accountId, password);
    system.debug('Portal user created: ' + userId);
}

Currently it keeps creating users with the default profile type instead of the ones specified by u.ProfileId. I am seeing that the debug log is printing out the "Value X found. Assigning profile Id."

Anyone come across something like this? Is it even possible to do what I am doing. I cannot take off the default profile setting or else self-registration is not possible.

Thanks in advance.

2
  • Are the 4 additional profiles added to the portal as portal profiles? Commented Mar 7, 2014 at 9:47
  • Yeah they are and all have different Sharing Sets applied to them in the customer portal.
    – Chris
    Commented Mar 12, 2014 at 12:36

1 Answer 1

1

Looks like the Site.createPortalUser neglects the provided profile and always sets the default profile.

Why don't you add these lines (you'll probably have to put them in @future context):

User updateUser = new User(Id=userId,profile=u.profileId);
update updateUser;
1
  • I see what you are saying now. Let the user be created and then after the Site.createPortalUser run the future method that updates the user to the correct profile. I am going to try this. I appreciate you help!
    – Chris
    Commented Mar 12, 2014 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .