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
Linga_RaminLinga_Ramin 

Unable to cover below Custom Setting in test class.How to fetch custom setting data to test class?

 Type__c theRec = Type__c.getInstance(op);  // Custom Setting
            if(theRec != null && theRec .Duration__c == true){
                 map<String,Product__c> mapData = new Map<String,Product__c>();
                 for(Product__c lstRev:Database.query(strFinalQuery)){ 
                   mapData.put( lstRev.Period__c, lstRev);
                }
Maharajan CMaharajan C
Hi,

Insert the Record for custom Setting in test class methods before the custom setting refered then it will cover you code:

@isTest
public class testClass {
 
 static testMethod void test() {
  // Add the remaining Fields and values for custom setting in below
  //The below will insert the record in Custom setting then you can refer the values 
  Type__c  obj = new Type__c (Name = 'Testing');
  insert obj;
  
  /*....Do your further Action after insert the Cusom setting.....
  ..............*/

 }
}

You can also use the Test Setup:  http://www.infallibletechie.com/2013/12/getting-null-values-from-custom.html

Thanks,
Maharajan.C