+ Start a Discussion
Raghu NaniRaghu Nani 

I am getting Error: First exception on row 0; first error: UNKNOWN_EXCEPTION, portal account owner must have a role

Hi All,
I am getting below error while creating the Community User
Error: First exception on row 0; first error: UNKNOWN_EXCEPTION, portal account owner must have a role.

I verified the Account owner Role. It was selected the role also.

Later i found that Account Owner is inactive.

In this senario how to create community user. Is i need to change Account Owner? Please confirm or any best solution.
Best Answer chosen by Raghu Nani
Prashant Pandey07Prashant Pandey07
Please mark the best answer to close the thread.


--
Thanks,
Prahsant

All Answers

Prashant Pandey07Prashant Pandey07
Hi Raghu,

How are you creating the user?

if you’re trying to create a Non-Role user, which includes part of creating Portal / Community User test data, the following error will be occured, that is because the portal account’s owner does not have a role to be assigned. 

The following sample code demonstrates how to avoid this error: You can run the below code in develoepr console and you will see the user is getting created with specific profile.
 
Account a = new Account(Name='Your Test Account Name');
  insert a;
 
  Contact c = new Contact(LastName = 'Your Contact Last Name', AccountId = a.id);
  insert c;
 
  User user = new User();
  user.ProfileID = [Select Id From Profile Where Name='Your community Profile Name'].id;//add your community profile here
  user.EmailEncodingKey = 'ISO-8859-1';
  user.LanguageLocaleKey = 'en_US';
  user.TimeZoneSidKey = 'America/New_York';
  user.LocaleSidKey = 'en_US';
  user.FirstName = 'Your first';
  user.LastName = 'Your last';
  user.Username = 'test@company.com';   
  user.CommunityNickname = 'testUser123';
  user.Alias = 't1';
  user.Email = 'no@email.com';
  user.IsActive = true;
  user.ContactId = c.Id;
 
  insert user;

--
Thanks,
Prashant
Raghu NaniRaghu Nani
Hi Prashanth,

Thanks for responding.

I Have existing Account and Contacts in the system

Recently we enabled the community portal. So our team is creating the users by clicking the Manage external user Button in contact.

Earlier I faced same error, so i updated the Role for Account owner. But yesterday I received same error message, when i cross verified Account owner has role but Owner is deactivated.
 
Prashant Pandey07Prashant Pandey07
In this case please make sure the owner has role..then it should work...

--
Thanks,
Prashant
Raghu NaniRaghu Nani
Hi,

Owner is having role, But User is in Active. Is this will cause the Issue?
Prashant Pandey07Prashant Pandey07
Yes..the owner should be active...

--
Thanks,
Prashant
Raghu NaniRaghu Nani
Is this any other Way to achieve without activating the Owner, Because the User not more in Organization.

Thanks,
Raghu
Prashant Pandey07Prashant Pandey07
Yes..and technically if the Account owner is not an active owner..then exsitance of an account doesn't make sence..there will be security issue..

--
Thanks,
Prashant
Raghu NaniRaghu Nani
Thanks Ok , I will inform team to change the Owner.
Prashant Pandey07Prashant Pandey07
Please mark the best answer to close the thread.


--
Thanks,
Prahsant
This was selected as the best answer