Skip to main content
ADMIN TBTC MC (AXIA) a posé une question dans #Apex
Hi ,

Can anyone please help me with test class for below trigger:

trigger CaseTrigger on Case (after insert , after update){

 if(Trigger.isAfter){

   if(Trigger.isInsert || Trigger.isUpdate){

    Set<Id> setIds = new Set<Id>();

    for(Case c :trigger.new){

    if(c.Delete_Case__c == true){

   setIds.add(c.id);

     }

    }

   if(setIds.size()>0){

   List<Case> listCaseToDelete = [Select Id from case where id in:setIds];

      delete listCaseToDelete;

      }

    }

  }

​}
3 réponses
  1. 1 nov. 2019, 07:30
    Hi SAroras,

    I have gone through your question. To make the test Class of Trigger you have to do the two DML operation in your Test Class i.e. insert and Update.

    Test Class of your Trigger with 100% code coverage is given below:-

    @isTest

    public class CaseTriggerTest {

        public testmethod static void caseTestMethod(){

            Case c = new Case();

            c.Origin = 'Phone';

            Test.startTest();

            insert c;

            c.Delete_Case__c = true;

            update c;

            Test.stopTest();

        }

    }

     

    I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

    Thanks and Regards,

    Deepali Kulshrestha

    www.kdeepali.com
0/9000