Activity Forums Salesforce® Discussions Other than SOQL and SOSL, what Is the way to get custom settings in Salesforce?

  • shariq

    Member
    September 19, 2018 at 7:47 am

    Hi,

    Other than SOQL or SOSL, Custom settings have their own set of methods to access the record.

    For example:

    If there is custom setting of name ISO_Country, SO_Country__c code = ISO_Country__c.getInstance(‘INDIA’);

    //To return a map of data sets defined for the custom object (all records in the custom object), //you would use: Map<String,ISO_Country__c> mapCodes = ISO_Country__c.getAll();

    // display the ISO code for India

    System.debug(‘ISO Code: ‘+mapCodes.get(‘INDIA’).ISO_Code__c);

    //Alternatively you can return the map as a list:

    List<String> listCodes = ISO_Country__c.getAll().values();

    Thanks

  • Parul

    Member
    September 19, 2018 at 9:33 am

    Hi,

    Adding some code snippet you can use:

    Here without querying from the record we can fetch the data from server and display in viusalforce page using custom setting.

     

    How to get the Value from custom setting

    public class DemoCustomSetting
    {
    public List<Country__c>getData {get;set;}
    public DemoCustomSetting ()

    {
    Map<String,Country__c>alldata= Country__c.getAll();

    getData = alldata.values();

    }

    }
    Visualforce page
    <apex:page controller="DemoCustomSetting" sidebar="false" >
    <apex:form >
    <apex:pageblock title="Person Details">
    <apex:pageblockTable value="{!getData }" var="A">
    <apex:column value="{!A.Name}"/>
    <apex:column value="{!A.State__c}"/>
    <apex:column value="{!A.City__c}"/>
    <apex:column value="{!A.Zip_code__c}"/>
    </apex:pageblockTable>
    </apex:pageblock>
    </apex:form>
    </apex:page>

     

    Hope this will help

    Thanks

  • Aman

    Member
    September 29, 2018 at 4:49 pm

    Hi,

    With the help of below mentioned code we can get custom settings:

    If there is custom setting of name Custom_Setting, Custom_Setting_c code = Custom_Setting_c.getInstance(‘Record’);

    //To return a map of data sets defined for the custom object (all records in the custom object), //you would use: Map<String,Custom_Setting_c> mapCodes = Custom_Setting_c.getAll();

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos