I have created the custom setting with the hierarchy type

I have added some fields to the custom settings

phone field is added to the custom settings

custom setting Name:Order_Configuration__c

Phone :12345 - one profile

phone:456798 - another profile

Is it possible to access the different values for different profiles in custom settings using apex trigger code

2 Answers 2


You use the CustomObject.getInstance method. You can provide the Organization Id, the Profile Id, or a User Id. Using this method, you can get the specific values for each User Id or Profile Id that has a specified hierarchy value.

  • @user36188 You can perform a query to determine which profile you want to find the Id for.
    – sfdcfox
    Nov 25, 2016 at 6:27
  • @user36188 String SellingOfficePhone = Order_Configuration__c.getInstance(UserInfo.getProfileId()).
    – sfdcfox
    Nov 25, 2016 at 6:35
  • @user36188 Yes, you have to query for the profiles first if you want to compare multiple profiles.
    – sfdcfox
    Nov 25, 2016 at 6:37
  • @user36188 Profile[] profiles = [select id from profile where name in ('profile 1','profile 2')]; String[] values = new String[0]; for(Profile Id: profiles) values.add(Order_Configuration__c.getInstance(id)); ... approximately.
    – sfdcfox
    Nov 25, 2016 at 6:39
  • @user36188 Using the getInstance function that's already been mentioned.
    – sfdcfox
    Nov 25, 2016 at 6:48
CustomSetting__c CS = CustomSetting__c.getInstance(ProfileId);

More info here:- https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_custom_settings.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.