You need to sign in to do that
Don't have an account?

Need Test class for simple after insert trigger
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;
}
}
}
}
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;
}
}
}
}
Greetings to you!
Please try below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
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
Use bellow code it may helpful for you
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com