Activity Forums Salesforce® Discussions How to query Custom settings in Salesforce Apex code?

  • Aman

    Member
    August 3, 2017 at 1:28 pm

    Hello shariq,

    There are two types of custom settings:
    List Custom Settings
    A type of custom setting that provides a reusable set of static data that can be accessed across your organization. If you use a particular set of data frequently within your application, putting that data in a list custom setting streamlines access to it. Data in list settings does not vary with profile or user, but is available organization-wide. Examples of list data include two-letter state abbreviations, international dialing prefixes, and catalog numbers for products. Because the data is cached, access is low-cost and efficient: you don't have to use SOQL queries that count against your governor limits.
    Hierarchy Custom Settings
    A type of custom setting that uses a built-in hierarchical logic that lets you “personalize” settings for specific profiles or users. The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value. In the hierarchy, settings for an organization are overridden by profile settings, which, in turn, are overridden by user settings.

    You can query Custom Settings using following Methods :

    List Custom Setting Methods
    The following are instance methods for list custom settings.
    getAll()
    Returns a map of the data sets defined for the custom setting.
    getInstance(dataSetName)
    Returns the custom setting data set record for the specified data set name. This method returns the exact same object as getValues(dataSetName).
    getValues(dataSetName)
    Returns the custom setting data set record for the specified data set name. This method returns the exact same object as getInstance(dataSetName).

    Hierarchy Custom Setting Methods
    The following are instance methods for hierarchy custom settings.
    getInstance()
    Returns a custom setting data set record for the current user. The fields returned in the custom setting record are merged based on the lowest level fields that are defined in the hierarchy.
    getInstance(userId)
    Returns the custom setting data set record for the specified user ID. The lowest level custom setting record and fields are returned. Use this when you want to explicitly retrieve data for the custom setting at the user level.
    getInstance(profileId)
    Returns the custom setting data set record for the specified profile ID. The lowest level custom setting record and fields are returned. Use this when you want to explicitly retrieve data for the custom setting at the profile level.
    getOrgDefaults()
    Returns the custom setting data set record for the organization.
    getValues(userId)
    Returns the custom setting data set record for the specified user ID.
    getValues(profileId)
    Returns the custom setting data set for the specified profile ID.

  • Parul

    Member
    September 16, 2018 at 1:42 pm

    Custom settings are like custom objects, but have an organization wide access. Data can be added in them like any Object, through APEX code, or by creating new record. However the access is available organization wide.

    There are two types of custom settings:

    List Custom Settings: A type of custom setting that provides a reusable set of static data that can be accessed across your organization.

    Hierarchy Custom Settings: A type of custom setting that uses a built-in hierarchical logic that lets you personalize settings for specific profiles or users.

    You can query Custom Settings using following Methods :

    List Custom Setting Methods
    The following are instance methods for list custom settings.
    getAll()
    Returns a map of the data sets defined for the custom setting.
    getInstance(dataSetName)
    Returns the custom setting data set record for the specified data set name. This method returns the exact same object as getValues(dataSetName).
    getValues(dataSetName)
    Returns the custom setting data set record for the specified data set name. This method returns the exact same object as getInstance(dataSetName).

     

    Thanks

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos