Activity Forums Salesforce® Discussions How can we access the custom setting in test class without using the seeAllData = true in Salesforce?

  • Tanu

    Member
    September 22, 2016 at 5:53 am

    Hi Mohit,

    Custom settings are nothing but an object .All you need in Test Class is instantiate the custom settings object and create the records of the custom settings and insert it in Test class itself.Make sure you bulkify your insert call.

    For example-

    list<SFA_ContactFields__c> lstContacts=new list<SFA_ContactFields__c>();//bulk List of custom setting object for bulk insert

    SFA_ContactFields__c csContactFields=new SFA_ContactFields__c(); //Custom Setting for Contact Fields
    csContactFields.Name='CreatedDate';//Static record 1 of custom setting
    lstContacts.add(csContactFields);

    SFA_ContactFields__c csContactFields1=new SFA_ContactFields__c();
    csContactFields1.name='IsDeleted';//Static Record 2 of custom settings
    lstContacts.add(csContactFields1);

    insert lstContacts;

    I think this help you.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos