+ Start a Discussion
Sam.arjSam.arj 

portal account owner must have a role: []

Hi,

 

I have setup my customer portal and a form (visualforce page) by which the user (after login / register) can update his/her profile.

 

Fields such as First Name, Last Name and Company Name is prompted and the user can update those.

 

As part of requirement I need to update the contact record associated with the "user" record as user updates his/her profile (above fields).

 

Also If the CompanyName has changed I need to create a new Account and link the contact to the new Account.

 

trigger UpdateContactFromPortalUser on User (after update) { List<Contact> contactsToUpdate = new List<Contact>(); List<string> AccountNames = new List<string>(); List<Account> Accounts = new List<Account>(); Map<String, Account> NewAccounts = new Map<String, Account>(); for(User u : Trigger.new) { String contactId = u.ContactId; if (contactId!=null && contactId!='') { AccountNames.add(u.CompanyName); } } if (AccountNames.size() > 0) Accounts = [SELECT id, name FROM account where Name in :AccountNames]; for (User u : Trigger.new) { String contactId = u.ContactId; if (contactId!=null && contactId!='' && u.PortalFlag__c == true) { Contact c = new Contact(Id=contactId); c.Email = u.Email; c.Salutation = u.Salutation__c; c.FirstName = u.FirstName; c.LastName = u.LastName; c.Title = u.Title; c.Phone = u.Phone; c.MailingStreet = u.Street; c.MailingCity = u.City; c.MailingState = u.State; c.MailingPostalCode = u.PostalCode; c.MailingCountry = u.Country; c.Department = u.Department; boolean AccountFound = false; for(Account acc : Accounts) { if (acc.Name == u.CompanyName) { c.AccountId = acc.Id; AccountFound = true; break; } } if (!AccountFound && (u.CompanyName != null && u.CompanyName != '')) { NewAccounts.put(c.Id, new Account(Name=u.CompanyName)); } contactsToUpdate.add(c); } }//loop if (contactsToUpdate.size()>0) { if (NewAccounts.size()>0) { List<Account> newaccs = NewAccounts.values(); insert newaccs; NewAccounts.putAll(newaccs); for(Contact c : contactsToUpdate) if (NewAccounts.get(c.Id) != null) { c.AccountId = NewAccounts.get(c.Id).id; } } for(Contact c : contactsToUpdate) { Utils.UpdateContact(c.Id, c.AccountId, c.Email, c.Salutation, c.FirstName, c.LastName, c.Title, c.Phone, c.MailingStreet, c.MailingCity, c.MailingState, c.MailingPostalCode, c.MailingCountry, c.Department, c.HomePhone, c.OtherStreet, c.OtherCity, c.OtherPostalCode, c.OtherState); } //update contactsToUpdate; }//contactsToUpdate end if }

 

 

 I tired two ways of doing this, one to process the records and directly update the contacts and second solution to right a method with @future prefix so that the contact records would get updated asynchroniously.

 

My problem is that at some Occassional cases I receive an error as below but NOT ALL THE TIMES!!

 

Debug Log:
System.DmlException: Update failed. First exception on row 0 with id 0038000000lmYXtAAM; first error: UNKNOWN_EXCEPTION, portal account owner must have a role: []

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Sam.arjSam.arj

Yeah all checked.

 

Everything is ok and the owner of the contact is always set as the site owner which has a role.

 

In my code, after registration, I look at the companyName field of the user and create an account for that contact (if does not exists).

The account owner is always set to the portal user. portal user receives a role upon registeration as far as I know, so this should not be it either.

 

To make the story short this was a bug, the latest release took care of it. I longer receive these error messages!

There are gone alltogether.

Message Edited by Sam.arj on 10-19-2009 10:11 AM

All Answers

David VPDavid VP

This happens when the portal accounts owner does not have a role assigned to him/her.

 

Check who the owner of the record is and make sure that user has a role defined.

Sam.arjSam.arj

Thanks David.

 

Maybe I have trouble understanding who the  "portal accounts owner" is?

 

I assume the portal account owner is the "Site Contact" that you set in the Site settings page.

 

In this case, the user already has a role. I have checked numerous times!

David VPDavid VP

Every record in salesforce has an owner that points to a user record.

 

In this case you need to look at the Account records and their owners. Make sure they all have a role assigned to them.

arunkarunk

Hi,

 

 

If you are using sites, you must have hard coded an accountId to the file SitesRegistrationController.

Owner of this Account should have a role.

 

If you have done this in some other way, just keep in mind that every user that registers through SItes is associated with a Account. Owner of all such accounts must have a Role defined.

 

 

Regards,

Arun 

Sam.arjSam.arj

Yeah all checked.

 

Everything is ok and the owner of the contact is always set as the site owner which has a role.

 

In my code, after registration, I look at the companyName field of the user and create an account for that contact (if does not exists).

The account owner is always set to the portal user. portal user receives a role upon registeration as far as I know, so this should not be it either.

 

To make the story short this was a bug, the latest release took care of it. I longer receive these error messages!

There are gone alltogether.

Message Edited by Sam.arj on 10-19-2009 10:11 AM
This was selected as the best answer