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

After Update Trigger(unable to fetch records when condition is written)
Hello All,
I am trying a write a trigger on contact object .My scenario is i have a check box in contact obj inactive contact and when it is checked true my trigger should delete the existing contact in child object.i tried to fetch id of the contact,in run time i am facing an error "System.FinalException: Record is read-only".Below is my code
rigger delsitecotact on Contact(after update) {
set < id > cts = new set < id > ();
for (Contact ci: trigger.new)
if(ci.Inactive_Contact__c = true)
cts.add(ci.id);
system.debug('list of contacts' + cts);
List < Site_Contact__c > resultList = [SELECT id, Contact__r.name, Contact__r.id, name FROM Site_Contact__c where Contact__r.id IN: cts];
if (!resultList.isEmpty()) {
delete resultList;
System.debug('deleted list of contacts ' + resultList[0].id + ' name is ' + resultList[0].Name);
}
Regards,
Krishna.
}
I am trying a write a trigger on contact object .My scenario is i have a check box in contact obj inactive contact and when it is checked true my trigger should delete the existing contact in child object.i tried to fetch id of the contact,in run time i am facing an error "System.FinalException: Record is read-only".Below is my code
rigger delsitecotact on Contact(after update) {
set < id > cts = new set < id > ();
for (Contact ci: trigger.new)
if(ci.Inactive_Contact__c = true)
cts.add(ci.id);
system.debug('list of contacts' + cts);
List < Site_Contact__c > resultList = [SELECT id, Contact__r.name, Contact__r.id, name FROM Site_Contact__c where Contact__r.id IN: cts];
if (!resultList.isEmpty()) {
delete resultList;
System.debug('deleted list of contacts ' + resultList[0].id + ' name is ' + resultList[0].Name);
}
Regards,
Krishna.
}
You are trying to set a value for Inactive_Contact__c to true in line
if(ci.Inactive_Contact__c = true) // which is trying to edit a locked record.
Please try changing it to
if(ci.Inactive_Contact__c == true)
or
if(ci.Inactive_Contact__c)
Please mark it as solved if it helps you solve the problem or let me know if it did not help you.
Thanks.