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


As far as hard coding in code, it doesn't have to be. You can a string from anywhere. For example, we use a custom setting that we can use to resolve URLs. This helps with managing our sandboxes, each of which integrates with a test environment used before updates are pushed to production.

You could also use custom labels, which can be resolved without queries. In either case, this form of usage lets our administrators adjust the endpoint in real-time. They can be updated via the API, though, so you could build a Visualforce page to manage those settings. The remote site settings are a protective measure, so I'm pretty sure you wouldn't necessarily want it to be dynamic.

Basic Example:

public class Utils {
    public static string getEndpoint(String name) {
        URL__c setting = URL__c.getValues(name);
        if(setting != null) {
            return setting.URL__c;
        return null;

This is a very basic example of a utility class that might resolve an endpoint from a custom setting. More complex examples might also detect the current sandbox/production environment, or possibly even check RemoteSite settings to make sure the URL is valid and/or create/update the setting.

  • that sounds good, thank you , Do you have any example that I can go through Once.
    – Ashish
    Apr 17 '15 at 21:22
  • @Ashish It doesn't have to be complex. See example. More advanced ideas would be more specialized to specific situations.
    – sfdcfox
    Apr 17 '15 at 21:51

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.