Thursday, March 13, 2014

Accessing Custom Settings


You can access custom settings from formula fields, validation rules, Apex, and the SOAP API.

Only the hierarchy custom settings can be accessed from the Formula fields
Syntax: {!$Setup.CustomSettingName__c.CustomFieldName__c}.
 Eg:  {!$Setup.Twillo__c.AccessLogin__c}

Accessing List Custom Setting

To get the list custom setting Dataset values

Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll(); 

This will store the data in the map which is a key value pair. Key will be the name of the data. 

 You can access all the list custom setting values using : 
 List<CustomSettingName__c> objectinstance=CustomSettingName__c.getAll().values() 

 this will be a collection of list.
From this you can access the specific data set value. 

 CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);


From the above example the data_set_name name will be asas

Accessing Hierarchy Custom Setting

To get the hierarchy custom setting Dataset values
 CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();

 if you do specified any profile to the custom setting. 
Then access the custom setting in the following way 
 CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID); 

 Use the Privacy as Public if the custom setting are to be exposed to the API.

No comments:

Post a Comment