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
sami amisami ami 

Query from list custom settings

Hi

 

I am trying to query my endpoint from custom setting in my RESTFULL call.

I created a object and a customfield in custom setting and made it public.

I gave my endpoint in that customfield(asdefaultvalue).

In my apex class Icreated a list and trying to query that field from that object.

But Iam getting nullvalue. Please help if I am missing something.

 

Best Answer chosen by Admin (Salesforce Developers) 
sami amisami ami
Thank you ..This is code which is working .

String endpoint=Customsetting__c.getInstance('label of field').API name of field__c ;


All Answers

TejTej

u should do some thing like this;

 

MyCustomSettingsobject__c obj = MyCustomSettingsobject__c .getInstance('name of the custom settings');

 

String url = obj.field__c;

 

system.debug('-----------------------------url---->'+url);

Siddhant IndraSiddhant Indra

Please refer below code for retriving List Custom Setting Value

When you add data in list custom setting there is one record created for it. Pass that record name to getValues('RecordName') function. you get instance og it.

 

myCustomSetting__c myCustomSetting = myCustomSetting__c.getValues('RecordName');
String dataValue = (myCustomSetting.customField__c != null) ? myCustomSetting.customField__c : '';

 

I hope this works for you.

 

 

 

sami amisami ami
Thank you Tej.But it didnt work.
What should be the name of custom settings?My API name of custom setting or field API name??
Both the ways my log is showing null in this line..
MyCustomSettingsobject__c obj = MyCustomSettingsobject__c .getInstance('name of the custom settings');
Any help where i am going wrong?Thank you in advance
sami amisami ami
Thank you siddhant....
Same issue with your code.I am getting mycustomsetting value in log as null.Guess i am missing something.could you please correct me.?
TejTej

setup-->develop--> custom settings --> click manage on ur custom setting --> u see the name of ur custom setting

 

just copy paste.

sami amisami ami
Thank you ..This is code which is working .

String endpoint=Customsetting__c.getInstance('label of field').API name of field__c ;


This was selected as the best answer