I go to the Accounts page and start creating a new account. I fill up this form and press 'Save". At the next page I click on "Enable Customer User" and after that I see the information of a user including the name of a Role that seems to be dynamically created and that also is not existent in the UserRole table. How this could be happening? The system is able to save the user information in this case. (we use person accounts)

Thanks Jose

2 Answers 2


In this About Customer Portal User Management help page, under Customer Portal Role Hierarchy,

When you enable a Customer Portal on an account, the system creates a role hierarchy for the account’s portal users. The portal roles are unique for each account and include the account’s name—or example, “Account A Customer User.” In your organization’s overall role hierarchy, this account-specific hierarchy is directly below the account owner.

What you experience is the default behavior of Salesforce while creating Customer portal users. If you want to see the Customer Portal roles, go the role of the Account Owner and then you can see the hierarchy under that role.


If you are creating portal user in test class, you don't need to assign role to the user. Once you assign a contact associated with an account to contactId field of the user and insert it, salesforce will automatically assign the role to the user based on the account name as mentioned(Account A Customer User) in the help document

Hope it helps.

  • Thanks for the answer. I was about to ask you about how to access those roles using apex. A friend of mine told me to get that info from a user using that role. Hope this will works!
    – Jose
    Commented May 11, 2016 at 15:23
  • I will have Ask: Do you know how can those roles be assigned to a User from Apex? I am having a hard time getting the next error: JosecczJITHandlerTEST.createUserTEST System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Invalid role assignment.: []
    – Jose
    Commented May 11, 2016 at 21:52
  • Take a look at my updated answer. You don't have to explicitly assign role to customer user. Salesforce will do that from the contact's account Commented May 11, 2016 at 22:04
  • Thanks again... But I tried that i.e. I created U, and A, assigned u.ContactId = [select PersonContactId FROM account where ID =: accountId].PersonContactId; I tried to insert this U but this failed asking to give a value to the UserRoleid. Any ideas?
    – Jose
    Commented May 11, 2016 at 22:20

My goal was to be able to use those automatically created role(s) to create and insert a User W. As they depend on who is logged (let's call this guy UL) I decided to use runas(UL) and a person account and user Up created by UL from the salesforce interface. From Up I got the role ID and profile Id info for W. Having this info I was able to insert W in test mode.

You must log in to answer this question.

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