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
Chinmay AbhangraoChinmay Abhangrao 

I want to know how to write test class if the trigger contains Custom Settings like IsActive Checkbox?

I have written this trigger :-

    CustmSettOnTrig_Camp__c obj=CustmSettOnTrig_Camp__c.getInstance();
     if(obj.isActive__c==true ){                         //Bold lines denote the custom setting provided by me and i want this line should be tested in the                                                                                     test class
         Set<id> accId =new Set<id>();
         list<Account> listAccToUp =new list<Account>();
        if(Trigger.isInsert ||Trigger.isUpdate){
//some code.. }

And i have written test class for that is :-

@istest public class TestClass_ForTrig_OnCamp {
    @istest public static void createCampaign(){
        CustmSettOnTrig_Camp__c obj=CustmSettOnTrig_Camp__c.getInstance();
        obj.isActive__c=true; //Something wrong here if i commit the custom setting in trigger the code coverage is 70% and if i didnt commit that                                                          code then the code covergae is 8%
      //some code  

Best Answer chosen by Chinmay Abhangrao
Hi Chinmay,

Same like object you can create custom setting data, then it will cover your code:
public static testMethod void myTest() {

CustmSettOnTrig_Camp__c  obj = new CustmSettOnTrig_Camp__c();
obj.isActive__c= true;
insert obj; 


Mark solved if it does help you