+ Start a Discussion
JPClarkJPClark 

How do you retrieve a Custom Setting in Apex

I have a Custom Setting object (hierarchy style) that has two fields of  'Email' types. I've added values to them at the ORG level, and nothing at the profile or user level. I want to retrieve one of the email values as a string in Apex. Thinking these were static objects, just get the values from them.

 

Since there isn't an update to the IDE addin yet for Winter 10, had to add this code using the web editor:

String userEmail = i360_eLead_Settings__c.Appointment_Request_Notification__c; User userId = [SELECT ID FROM User WHERE Email = :userEmail];

 

 

This code gives us:

ErrorError: Compile Error: Illegal assignment from Schema.SObjectField to String at line 67 column 9 

 

 

So I tried using the r instead of c:

String userEmail = i360_eLead_Settings__r.Appointment_Request_Notification__c;

 

 

And received:

ErrorError: Compile Error: Variable does not exist: i360_eLead_Settings__r.Appointment_Request_Notification__c at line 67 column 28 

 

 

I have not been about to find any examples for using these custom settings.

Has anyone found out how these work?

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
JPClarkJPClark

I know, RTFM:

 

i360_eLead_Settings__c oneInstance = i360_eLead_Settings__c.getInstance(); string userEmail = oneInstance.Appointment_Request_Notification__c;

 

 

 

All Answers

aalbertaalbert
Here is a link to the Apex docs specific to Custom Settings Methods.
JPClarkJPClark

I know, RTFM:

 

i360_eLead_Settings__c oneInstance = i360_eLead_Settings__c.getInstance(); string userEmail = oneInstance.Appointment_Request_Notification__c;

 

 

 

This was selected as the best answer
JPClarkJPClark
Thanks, Andrew, I was right behind you.