You need to sign in to do that
Don't have an account?
![Chinmay Abhangrao Chinmay Abhangrao](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
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
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
Same like object you can create custom setting data, then it will cover your code:
Mark solved if it does help you