I have a custom CB field on the contact record called connect_america_account__c
. When the value of this contact field is true, I would like the CB field value on the related account, also called (connect_america_account__c
) to also be true. Here is the code I've constructed:
trigger ConnectA on Contact (after insert,after update) {
List<Id> AccID = New List<Id>();
for(Contact con : Trigger.new){
if(con.connect_America_Account__c = true && con.AccountId != null){
AccID.add(con.AccountId);
}
}
List<Account> accList = [SELECT Name, BillingStreet FROM Account WHERE id in :AccID];
for(Integer i = 0; i < accList.size(); i++){
accList[i].connect_America_Account__c = true;
}
update accList;
}
Here is the error message:
Error:Apex trigger ConnectA caused an unexpected exception, contact your administrator: ConnectA: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.ConnectA: line 9, column 1