Sunday 28 July 2013

Hierachy Custom Settings in Salesforce

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.

Hierarchy custom settings can be configured at varying user specificity levels under a single name; the platform will look for the most specific configuration first, then fall back / inherit to the least specific that is why the lowest level of data in the custom setting is specified at the user level.
- setting per user,
- setting per profile,
- setting for whole org,

 Id pid = Userinfo.getProfileId(); // Getting profile of current user.  
 //Obtain values from Custom Settings  
 HierarchyExampleSettings__c arc = HierarchyExampleSettings__c.getInstance(pid);  
 String exampleURL = arc.Site_URL__c; // Setting variable from custom setting  
 String examplePage = arc.Example_Page__c;  
getInstance(ID) : 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.

No comments:

Post a Comment