Thursday, October 25, 2012

Creating Custom Setting record using APEX

Since API 24, you cannot use existing Salesforce data in your test classes until you set SeeAllData to true. (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_data_access.htm)

Hence you would require data in Custom Settings too to be available to your code. Creating a new record for Custom Settings is also same as that for any other Standard or Custom Object.

Custom_Settings__c cs = new Custom_Settings__c (Name='Owner_Name', Value__c='HS');
insert cs;


3 comments:

  1. What about List custom settings, any idea how to create them?

    ReplyDelete
  2. This code is for the List custom settings only.

    ReplyDelete
  3. I get an error saying "Invalid type: Custom_Settings__c".

    ReplyDelete