Hi Manpreet,
Custom settings are similar to custom objects, where we can create custom object where can create custom field, store our data. Custom Settings are essentially custom objects that are exposed in the applications cache and are accessible via their own API.
Custom settings are of two types:
1. List custom settings
2. Hierarchy custom settings
List Custom Settings
Here can store our data and display that data without using soql.If we are using soql to fetch or display same record for multiple times it might hit governing limit ,to avoid that we can use list custom setting.
I have object named student__c where I need to fetch record on frequently basis. I am displaying record using soql.
List<student__c>stu= [select name, phone__c ,email__c, mark__c from student__c];
Salesforce runs Multi-tenant environment, so there is chances of hitting governor limit in salesforce,
If I store that in custom object I can fetch withoutusing soql.we can fetch data using custom setting methods,
Here customsetting object name is student__c
Public class Studentexample{
Public List<student__c>stuList{set;get;}
Public Studentexample(){
stuList= new list<student __c>();
Map<string,student__c>Mapstu=stu.getAll();
stuList=mapstu.values();
}
}
We can display that record in visualforce page
<apex:pageblocktable value={“!stuList”} var=”s”>
<apex:colum value=”{!s.name}”/>
<apex:colum value=”{!s.phone__c}”/>
<apex:colum value=”{!s.Mark__c}”/>
<apex:colum value=”{!s.Email__c}”/>
</apex:pageblocktable>
Hierarchy Custom Settings
This type of custom setting that help to customize settings for specific profiles or users. The hierarchy logic checks the organization, profile, and users. We can override profile or user organization per wide. We canby-pass validation to a particular profile or user.
Object name is Hierarchy Settingsexample__c
Hierarchy Settingsexample__c Hcs=HierarchySettingsexample __c.getInstance();
We can choose user by this method userInfo.getUserId();
We can choose profile by this method userinfo.getprofileid();
-
This reply was modified 7 years, 6 months ago by Louis.