Friday, September 14, 2018

Custom settings in salesforce


Custom setting are similar to custom object in salesforce,You can store some custom data inside this and can access this inside apex class avoiding use of multiple soql queries. 


Custom settings in salesforce


1)List custom settings 
2)Hierarchy custom settings

 List custom settings:



List custom settings


List custom settings have user-independent values.

Methods available with list custom settings are: 

1)getAll(); 
2)getValues(); 

Syntax: 

1) Map<Data_set_name, CustomSettingName__c> cus = CustomSettingName__c.getAll(); 

The getAll method returns values from all fields associated with list custom setting. 

2)CustomSettingName__c cus = CustomSettingName__c.getValues(Data_set_name); 

The getValues method returns values associated with specific data set. 

This method can be used with both list and hierarchy custom settings. 


Hierarchy custom settings: 


Hierarchy custom settings


Hierarchy custom settings let's you personalize setting for specific role and profile. 



Methods available with Hierarchy custom settings are: 

1)getOrgDefaults(); 
2)getInstance(); 

syntax: 


1)CustomSettingName__c cus = CustomSettingName__c.getOrgDefaults(); 

The above method returns values from dataset at organization level. 

2)CustomSettingName__c cus = CustomSettingName__c.getInstance(Profile_ID or UserID); 

The above method returns dataset values related to specific profiles.


SAMPLE EXAMPLE:

Let say we have custom setting called employee where we are storing employee roll number. 
Let's assume we have some employee information stored in custom setting. 
employee1     rollNo1 
employee2    rollNo2 

Syntax: 

Employee__c obj=new Employee__c.getvalues('employee1'); 
String rolNo=obj.rollNo1__c; 


**************************************************************************************************************


TAGS:custom settings in salesforce,Custom Settings Methods,Using List Custom Settings in Salesforce,hierarchy custom settings in salesforce.

**************************************************************************************************************

No comments:

Post a Comment