0

I am trying to cascade the same ownerid across all contact owners within an Account Contact Relation hierarchy. I wrote a pretty basic after update trigger on an account to accomplish this.

When all records are owned by the same person, it updates correctly. When there is a mix of ownerids, I receive "INVALID_FIELD, All accounts must have the same current owner and new owner.: [OwnerId]" Please note: Person accounts are enabled in this Org.

Basic Logic

 list<contact> Contacts = new list<contact>();
    for(AccountContactRelation r: [select id, 
                                   AccountId,
                                   contactid, 
                                   contact.ownerid, 
                                   contact.owner.Name 
                                   from AccountContactRelation 
                                   where AccountID in: AccountOwnerMap.keyset() 
                                  ]){
                                      system.debug('r: ' + r);
                                      if(r.AccountID!=null && AccountOwnerMap.containskey(r.AccountID)){
                                          Contact c = new Contact(id=r.Contactid);
                                          c.ownerid = AccountOwnerMap.get(r.AccountID);
                                          Contacts.add(c);    
                                      } 
                                  }
    system.debug('Contacts: ' + Contacts);
    //Update Contacts
    if(Contacts.size()>0){
        update Contacts;
    }

Similar issue with no clear answers below.

  • I am facing same issue, did you find any solution for this? – Muzammil Bajaria May 9 at 7:49
-2

You can call the update from within a future method to fix this problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.