Custom Setting Creation in Apex Test Class

Please refer following approach to insert/update custom setting record in test class.

@isTest(SeeAllData=FALSE)
private class YouTestClass {

    //Initialize custom settings to prevent test failures
    // replace Dreamhouse_Settings__c  = your custom setting name
    private static Dreamhouse_Settings__c customSettingInstance;
 
    static {
        customSettingInstance = new Dreamhouse_Settings__c();
        customSettingInstance.LIFX_Token__c = '';
        upsert customSettingInstance;
    }
 
    static testMethod void yourTestMethod() {      
        Test.startTest();
        //Your unit test here
        Test.startTest();
    }
}

I hope this will help you.

Comments

Popular posts from this blog

System.AsyncException: The Apex job named is already scheduled for execution.

Salesforce Trace Log Query Using Apex

AJAX Toolkit Debug Shell

How to Query All the batch classes in your Salesforce Instance using APEX

Prefix List Of Salesforce Object

Error : "Trigger must be associated with a job detail"

how to get object name from id / prefix value in salesforce

Recurring Scheduling Apex Job for every 10,15 etc minutes

Creating Salesforce Developer Account