function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sathishsfdcsathishsfdc 

populate custom setting value into opportunity object field

Hi,

I have a requirement wherein i have  flag__c<text field> in Opportunity Object. I need to populate into this field values based on the custom setting<have created a hierachiracl custom setting> and retreive it.
Can some one help me as to how to go about on this??
Thanks
sathish


 
KaranrajKaranraj
Sathish - You can able to get the hierarchical custom setting value in the apex class in the following ways,
CustomSettingName__c mhc = CustomSettingName__c.getInstance(pid); //where pid is the profile id/User id
string mPhone = mhc.CustomSettingFieldName__c ;
//If you want to return the data set for the organization then use getOrgDefaults
Hierarchy__c CS = Hierarchy__c.getOrgDefaults();
Check this link for how to use custom settings in apex class - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm
You can use userinfo.getProfileId() to get the profile Id of the current user and userinfo.getUserId(); to get the user of the current user in your apex trigger,Then make all your business logic in the apex code and assign the value that field.

Thanks,
Karanraj
Kristian HedeKristian Hede
Hi Satnish,

If it is a Hierarchy custom setting, you should be able to retreive it by pressing "Insert Field" on the Advanced Formula page of the formula field. The Hierarchy setting should look something like:

$Setup.<<Custom Setting API name>>

When you select the setting, you will be able to choose the fields as well. Alternately, you can just type in the reference in the following form:

$Setup.<<Custom Setting API name>>.<<Setting API name>>

Please note that List Custom Settings cannot be referenced in formula fields:

https://success.salesforce.com/ideaview?id=08730000000I5NsAAK

Be regards
Kristian