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

Dynamic endpoints in salesforce callout

Endpoints are always hard coded in remote settings and in the code, Is there a way that endpoints which I am hard coding can be dynamic .
So that If Target System url changes , I need not to make changes in code
Any Idea how to achieve this functionality?

Thank you
Best Answer chosen by Ashishyadav

You can create a List type custom setting to accomplish this. Create one custom setting and one field in that custom setting to hold the value of endpoint url.

Example: You have created one custom setting named as 'Test' and created one field of type URL named as 'End Point URL'. After that create one custom setting record by clicking the 'Manage' button on custom setting detail page. Give the name as 'Integration' and store the value of end point in URL field.

In code you can do following:
Test__c objtest = Test__c.getInstance('Integration');//here parameter should be name of custom setting record which you have created.
String endpoint = objtest.End_Point_URL__c;

FYI : This is a best practice to keep all hard coded values used within the code in the custom setting since these values could be changed when you migrate data from one org to another, probably from sandbox to production.