function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gheorghe SimaGheorghe Sima 

I want to change the Account related to an contact from apex

I want to change the Account related to an Account, but when i make the update on Contact's records it doesn't change the Account.
Can anyone help me?
That is my apex code.
User-added image

User-added image
Shrikant BagalShrikant Bagal
Please try following code:

 
List<Account> selectedAccount = new List<Account>(); 
for(mContact contact :contacts)
{
     if(contact.selected)
     {
           contact.contact.Account = Acc;
          selectedContacts.add(contact.contact.Account);
     }
}

Database.update(selectedContacts);

FYI:
It will update the Account related to Contact.


If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
 
Gheorghe SimaGheorghe Sima
It doesn't work...