You need to sign in to do that
Don't have an account?

System.FinalException: SObject row does not allow errors
trigger OnAccount_ConfirmToChange on Account (before update) {
List<Account> accList = [select Id,Name,(select AccountId,Name from Contacts) from account where Id = :Trigger.newMap.keySet()];
// Map<Id,Contact> conMap = new Map<Id,Contact>([select Id from Contact where AccountId in: accList.Id]);
List<Contact> conList = [select Name,isAccountChanged__c from Contact where AccountId in: accList];
for(Account acc:accList){
for(Contact con:conList){
if(conList.size() > 0){
if(con.isAccountChanged__c == false){
Account ar = Trigger.oldMap.get(acc.Id);
ar.addError('Only if the isAccountChanged is checked,You can modify the account!');
}
}
}
}
}
I think , this is how you cant do ,The problematic area is
List<Contact> conList = [select Name,isAccountChanged__c from Contact where AccountId in: accList];
acclist is the list of account (records) so it can't be used AccountId in acclist .
Moreover this conlist is not needed since those records are already there in acclist
Change as like this and give a try :
trigger OnAccount_ConfirmToChange on Account (before update) {
List<Account> accList = [select Id,Name,(select AccountId,Name from Contacts) from account where Id = :Trigger.newMap.keySet()];
for(Account acc:accList){
for(Contact con:acc.conList){
if(conList.size() > 0){
if(con.isAccountChanged__c == false){
Account ar = Trigger.oldMap.get(acc.Id);
ar.addError('Only if the isAccountChanged is checked,You can modify the account!');
}
}
}
}
}
kindlyt let me know incase the problem exists after this .