Search code examples
salesforceapex-code

Can I create a new remote site setting through apex code ?


I get the endpoint where the request has to be sent at runtime. Later i want to send an HTTP post request to this endpoint, so I have to create a remote site setting too at runtime.

Is there a way to create a remote site setting through apex code?


Solution

  • I don't believe there is a way to do what you're asking (I couldn't find one). To allow creating Remote Site Settings using Apex would create a lot of security problems; that is probably why it's not allowed.

    However, I was able to find a question and answer with some recommendations that relate to this question.

    "The best way I've found to save configuration values is to use Apex Custom Settings. To set the Remote Site settings programmatically you could use the Metadata API." - Adam