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
AbAb 

Querying a custom setting

Hello,

I have a custom object like 
Name and link.

How is it possible to get the link when i will pass Name.

In Apex i want to query a custom settingto get the link

thaks for suggestion
Best Answer chosen by Ab
v varaprasadv varaprasad
Hi Sandrine,


please check below code once and let me know if any issues is there.
 
customesettingnme myCS1 = customesettingnme.getValues('name');
 String myCCVal = myCS1.link__c;
 system.debug('========'+myCCVal);
 
 customesettingnme myCS2 = customesettingnme.getInstance('name');
 String myCCInst = myCS2.link__c;
 system.debug('========'+myCCInst);
 
 
 
 system.assertEquals(myCCinst, myCCVal);

Thanks
Varaprasad

All Answers

v varaprasadv varaprasad
Hi Sandrine,


please check below code once and let me know if any issues is there.
 
customesettingnme myCS1 = customesettingnme.getValues('name');
 String myCCVal = myCS1.link__c;
 system.debug('========'+myCCVal);
 
 customesettingnme myCS2 = customesettingnme.getInstance('name');
 String myCCInst = myCS2.link__c;
 system.debug('========'+myCCInst);
 
 
 
 system.assertEquals(myCCinst, myCCVal);

Thanks
Varaprasad
This was selected as the best answer
LBKLBK
Hi Sandrine,

Here is the sample APEX code.
 
YOUR_CUSTOM_SETTING__c objCustomSetting = YOUR_CUSTOM_SETTING__c.getValues('NAME_OF_THE_ENTRY');
String sLink = objCustomSetting.link__c;
YOUR_CUSTOM_SETTING__c is the name of your custom setting.

NAME_OF_THE_ENTRY is the actual name you have provided when you created an Entry in the custom setting (If you can find this by clicking on Manage button in the Custom setting screen).

Let me know if this helps.
 
Arvind KumarArvind Kumar
Hi Sandrine,

You can use get name with below query.
 
CustomSetting CS = CustomSetting .getValues('United States');
String myCC1 = CS.Link__c;
CustomSetting CS2 = CustomSetting .getInstance('United States');
String myCC2 = CS2.Link__c;
system.assertEquals(myCC2, myCC1);


Please check the below links for more examples of custom settings.

http://blogatsalesforce.blogspot.sg/2015/03/use-custom-setting-efficiently-in-apex.html


https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm#apex_methods_system_custom_settings)


Thanks,

Arvind Kumar