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
Baylor PeakBaylor Peak 

Help with custom setting to store URL please?

Hello all,

I am storing my enpoint for a REST callout inside a custom setting called MyCustomSettings with Name of 'default'. One of the fields inside the custom setting is a type URL field called 'endpoint' with 'test.com' for the value.

In my code, I have:

MyCustomSettings__c myCS1=MyCustomSettings__c.getValues('default');
        string endpoint=myCS1.endpoint__c;
		request.setHeader('Authorization',authorizationHeader);
		request.setHeader('Content-Type','application/json');
		request.setEndpoint(endpoint);

When I test my code I am getting this error:

System.NullPointerException: Argument 1 cannot be null

What am I missing please?:)

 

ANUTEJANUTEJ (Salesforce Developers) 
Hi Baylor,

Have you tried checking if it working fine if you directly give the url?

Also, can you once have a look at the below code which I think might be a similar implementation: [https://salesforce.stackexchange.com/questions/45149/how-to-access-custom-setting-url-field-in-apex]

In case if this came in handy can you close the thread and please mark this as the best answer so that it can be used by others in the future and also helps in keeping our community clean.

Regards,
Anutej
Baylor PeakBaylor Peak
Could you please tell me how this works with a List Custom Setting? Your example is for a hierarchy. What I am asking is first in the Custom Setting under setup, do I need to make this a type URL field? Also how do I format my URL inside the value, do I just put http://test.com? Or do I put ‘http://test.com’ inside quotes?
ANUTEJANUTEJ (Salesforce Developers) 
I tried a similar scenario but I was not able to find URL field in my custom settings under setup however I tried to send a request to the end point via code and I put this in the code [ request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');  ]

I followed  https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts article to get to know about setting the endpoint in the code.