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
Mahesh Babu 187Mahesh Babu 187 

After delete trigger Test Class

Hi Team,

Please help to write a test class for a after delete trigger.


trigger MaketheCheckboxUnused on Order_Line_Item_Serials__c (after delete) {
    List<Serial_Number__c> snumlist = New List<Serial_Number__c>();
    List<Id> orderitemlist = New List<Id>();
    For(Order_Line_Item_Serials__c oli : Trigger.Old){
    List<Serial_Number__c> Olis = 
        [Select Id, Name,Serial_Number__c,  
         From Serial_Number__c Where
         Status__c = TRUE AND
         ID IN : orderitemlist];
    For(Order_Line_Item_Serials__c orim : Trigger.Old){
        For(Serial_Number__c olisn : Olis){
                olisn.Status__c = FALSE;
    update snumlist; 

Thanks in Advance,

Foram Rana RForam Rana R
Hi Mahesh,

go through the below link.

Foram Rana
ANUTEJANUTEJ (Salesforce Developers) 
Hi Mahesh,

You can use something as mentioned in the below link for reference to develop a test class for your use case.


I hope this helps in case if this comes handy can you please choose this as best answer so that it can be used by others in the future.

Mahesh Babu 187Mahesh Babu 187
Hi Anutej,
I used the same link for my reference. But I didn't understand. I have tried to write a code but it doesn't cover anything.

Test Class

public class TestMaketheCheckboxUnused {
  static testMethod void MaketheCheckboxUnused_Testmethod() {
          Order_Line_Item_Serials__c oli = new Order_Line_Item_Serials__c();
          Serial_Number__c sn = new Serial_Number__c();
          sn.Serial_Number__c = 'SR-2021';
          sn.Status__c = true;
          sn.Id = oli.Id;
          insert sn;
      List<Serial_Number__c> Olis = [Select Id, Serial_Number__c from Serial_Number__c where
         Status__c = TRUE AND Id=: oli.Id];
      delete Olis;
      sn.Status__c = false;      

Please help me to modify this code.