Print this page

Error – Portal account owner must have a role

Knowledge Article Number 000175522
Description End user gets the error "UNKNOWN_EXCEPTION, portal account owner must have a role: []" when trying to enable a contact as a partner or customer portal user.
Resolution
This error is generated because the user was not assigned a role. 
You will also see this same error (for the same reason) when trying to enable a contact as a partner or customer portal user.
 
The following sample code demonstrates how to avoid this error:
 
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
  }
 
 




promote demote