Find your content:

Search form

You are here

Can I access Remote Site List from Apex?


Our application makes outbound connections to different remote sites, and installs a short list of those sites as part of the Package Installation process.

One of our custom objects is a list of accounts to access on those servers (username, password, hostname). We just ran into a problem where someone mistyped a server hostname when adding an account.

I'd like to have a trigger before insert and modify that throws an error if the user tries to add an entry for a host that isn't in the Remote Site List. The error will state that they need to either change the hostname or add the site to the Remote Site List.

The trigger won't be able to make a callout, otherwise I could just try calling out and trapping the exception. Even if I can't walk the list of Remote Sites, it'd be great to call an API that tells me whether a given URL is in there or not. For example, if HttpRequest.setEndpoint() threw an exception without having to call Http.send().

Attribution to: tomlogic

Possible Suggestion/Solution #1

The remote sites list is not currently exposed in Apex.

Attribution to: Ryan Guest

Possible Suggestion/Solution #2

Your list of remote sites should be a pretty static list, right? If so you could just make hostname a picklist that the user can choose from. You could also add a validation rule to ensure they don't add invalid options to the picklist and attempt to select them.

Attribution to: Tim Smith
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content