Skip to main content
ADMIN TBTC MC (AXIA) 님이 #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개
  1. 2019년 11월 1일 오전 7: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