function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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)
    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.
}
Best Answer chosen by krishna chaitanya 35
Malni Chandrasekaran 2Malni Chandrasekaran 2
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.