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

trigger MaketheCheckboxUnused on Order_Line_Item_Serials__c (after delete) {
     //Serial_Number__c    
    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){
        orderitemlist.add(oli.Serial_Number__c);
    }
    List<Serial_Number__c> Olis = 
        [Select Id, Name,Serial_Number__c,  
         Product__r.Id,Status__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){
            If(Trigger.IsDelete){
                olisn.Status__c = FALSE;
                snumlist.add(olisn);
            }
        }
    }
    update snumlist; 
}

Thanks in Advance,
Mahesh


 
Foram Rana RForam Rana R
Hi Mahesh,

go through the below link.
https://developer.salesforce.com/forums/?id=906F0000000BIhDIAW

Thanks,
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.

>> https://developer.salesforce.com/forums/?id=906F0000000BIhDIAW

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.

Regards,
Anutej
 
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

@isTest
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;
      
       Test.startTest();
      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;      
      Test.stopTest();
}
}

Please help me to modify this code.

Thanks,
Mahesh