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

Labels

visualforce page ( 13 ) apex integration ( 5 ) apex trigger ( 4 ) csv file from vf page ( 4 ) javascript ( 4 ) csv visualforce page ( 3 ) Too many ( 2 ) call out ( 2 ) integration ( 2 ) rest api ( 2 ) salesforce rest api ( 2 ) salesforce to salesforce integration ( 2 ) sfdc rest api ( 2 ) trigger ( 2 ) 15 digit to 18 digit ( 1 ) DML rows in Apex ( 1 ) Date Conversion ( 1 ) Date/Time conversion ( 1 ) Deploy ( 1 ) Objects to Future Annotated Methods ( 1 ) SFDC limits ( 1 ) Sobject to Future Annotated Methods ( 1 ) Test Class ( 1 ) TimeZone Conversion ( 1 ) Too many dml rows ( 1 ) Too many future calls ( 1 ) annotations ( 1 ) apex code ( 1 ) closed opportunities ( 1 ) commit ( 1 ) convert ( 1 ) create records ( 1 ) csv create records ( 1 ) custom setting ( 1 ) deployment ( 1 ) deployment changeset ( 1 ) disable apex class ( 1 ) disable apex trigger ( 1 ) disable in production ( 1 ) document ( 1 ) download ( 1 ) field name ( 1 ) formula fields ( 1 ) iframe ( 1 ) inactive ( 1 ) intellisense ( 1 ) jsforce ( 1 ) limits ( 1 ) matrix report in vf page ( 1 ) multi select ( 1 ) multi select salesforce ( 1 ) multiselect ( 1 ) paypal ( 1 ) picklist ( 1 ) record type ( 1 ) rollback ( 1 ) salesforce limits ( 1 ) salesforce list ( 1 ) salesforce map ( 1 ) salesforce rest ( 1 ) salesforce set ( 1 ) salesforce1 ( 1 ) sandbox deployment ( 1 ) sfdc collection ( 1 ) sfdc list ( 1 ) sfdc map ( 1 ) sfdc rest ( 1 ) sfdc set ( 1 ) uncommitted ( 1 ) updated field ( 1 ) user ( 1 ) validation rule opportunity ( 1 ) validation rules opportunities ( 1 ) vf page ( 1 )

Ad