Error – Portal account owner must have a role??
September 2nd, 2010
I wrote the following test class for a PRM deployment and received this crazy error when running the test:
System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, portal account owner must have a role: []
I searched the message boards but couldn’t find any reference to the real culprit. My original thought was that the user being created was causing an error somehow. However, the real problem was that my user was not assigned a role. Hopefully this post saves someone some time tracking down the solution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | Account a = new Account(Name='Test Account Name'); insert a; Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id); insert c; User user = new User(); user.ProfileID = [Select Id From Profile Where Name='Some Profile'].id; user.EmailEncodingKey = 'ISO-8859-1'; user.LanguageLocaleKey = 'en_US'; user.TimeZoneSidKey = 'America/New_York'; user.LocaleSidKey = 'en_US'; user.FirstName = 'first'; user.LastName = 'last'; user.Username = 'test@appirio.com'; user.CommunityNickname = 'testUser123'; user.Alias = 't1'; user.Email = 'no@email.com'; user.IsActive = true; user.ContactId = c.Id; insert user; System.RunAs(user) { // do all of my tests } |
You will also see this same error (for the same reason) when trying to enable a contact as a partner or customer portal user.
Categories: Apex, Salesforce














Jeff, I have seen this error too and driven myself mad trying to figure it out. Somewhere out there, someone is googling this issue right now.
One typo in your text though…you need to have a ROLE, not Profile.
And it may not need to be you…it’s whoever owns the records associated to the Partner user.
@Brian, thanks for the typo catch!
HI jeff,
What you just need to do is to assigned a role to the admin user of you org (admin will be the owner of the portal). Go you users select the user with system administrator profile org owner and assign any role to the user for eg, CEO and you are done. I will work fine.
As I understand it, this is tied into defining where the portal users fit into the overall role hierarchy, since they have some data sharing capabilities.
Jeff – this also happens if you attempt to use the “Enable Customer Portal User” from the “Work with Portal” button on a contact where the owner of the Account record the contact is attached to does not have a role.
To recreate this issue:
1) Log on as Administrator (without a role) and create an account named “Acme”
2) Log in as another user (with a role) and create a contact named “Joe Contact” from the Acme account detail screen.
3) From the “Joe Contact” detail screen click the pick button “Work with Portal” and select “Enable Customer Portal User”.
4) You will receive the error you mentioned.
5) Navigate to the Account detail for “Acme” and change the owner to the user you logged in as in step 2 and then repeat step 3. You will no longer get the error.
I agree the error message would make you think it had something to do with the portal configuration not a user role issue.