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

Trigger to delete the registration if checkbox is checked

I have written a trigger to automate deletion process if user checks the checkbox.

trigger checkCheckBox on Registration__c(after update) {
    //List to contain Registration(s) to be deleted.
    Registration__c[] toBeDeleted = new list<Registration__c>();

    for (Registration__c Register : {
       if (Register.Registration_cancel__c== True) {
    delete toBeDeleted;

The above code sample is throwing following exception:

caused by: System.SObjectException: DML statment cannot operate on or trigger.old
Trigger.deleteDeletedOrgs: line 10, column 1.

How to resolve this?
Best Answer chosen by ExploreForce
change like this

toBeDeleted.add(new Registration__c(id =;