+ Start a Discussion
krishna chaitanya 35krishna chaitanya 35 

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)
    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);

Best Answer chosen by krishna chaitanya 35
Malni Chandrasekaran 2Malni Chandrasekaran 2
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)

Please mark it as solved if it helps you solve the problem or let me know if it did not help you.