Hello friends i was updating ownerId records firstly when i give 'limit 1' i could change but after i wanted to change 10 record system gave error message
And i tell somethings about that am sending 2 parameter and my method making update in this way Accounts with Contacts Owners going the same
Below my error message:
System.DmlException: Update failed. First exception on row 0 with id 0031t00000BrpLpAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MC4SF.Contact: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a2b1t000000ZChTAAW; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: [] (MC4SF): []
Anon Apex Page:
List<Account> acc = new List<Account>();
acc = [SELECT OwnerId,Name From Account where Cari_Grup_Kodu__c IN('CO') Limit 2];
if(acc.size() > 0)
{
//List <String> Names = new List <String>();
//List<String> OwnerIds = new List <String>();
for (Account acc_i : acc)
{
//Names.add(acc_i.Name);
//OwnerIds.add(acc_i.OwnerId);
//ee.UpdateContactOwner(Names[i]);
EditRecordContacts.UpdateContactOwnerString(acc_i.Name,acc_i.OwnerId);
}
}
And Apex class page:
public class EditRecordContacts {
public static string UpdateContactOwnerString(String name,String OwnerIds)
{
system.debug(name);
system.debug(OwnerIds);
List<Contact> contacts = new List<Contact>();
contacts = [Select OwnerId,Account.Name From Contact WHERE Account.Name = :name];
if(contacts.size() > 0)
{
system.debug(contacts);
for(Contact coo_i : contacts)
{
coo_i.OwnerId = OwnerIds;
}
update contacts;
}
return name;
}
}