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

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

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

Prefix List Of Salesforce Object

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

Creating Salesforce Developer Account

15 to 18 char ID Conversion in Apex