Can we get all remote site settings in apex ?
I would like to check if a remote site setting exists or not.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityYou can use ToolingAPI to access the RemoteSiteSettings. This works either via Apex using this https://github.com/afawcett/apex-toolingapi or even via JavaScript using that approach http://andyinthecloud.com/2014/07/29/post-install-apex-metadata-api-configuration-solved/
Of course both options would require some serious understanding and adaption on your end.
The RemoteSiteSetting is not directly exposed in Apex. It is neither possible to query it, nor to instantiate it.
RemoteSiteSetting s = new RemoteSiteSetting();
results in Invalid Type
SELECT Id FROM RemoteSiteSetting
results in sObject type 'RemoteSiteSetting' is not supported.
If you use Salesforce Inspector (Chrome Extension) https://chrome.google.com/webstore/detail/salesforce-inspector/aodjmnfhjibkcdimpodiifdjnnncaafh?hl=en or other tool that allows you to query using the Tooling API, you can just query:
select id, SiteName, EndpointUrl from RemoteProxy
If using Salesforce inspector, make sure "Use Tooling API?" checkbox is checked.
There is a way to do it but it's messy and involves parsing and screen grabbing. The Metadata API could give me the remote site settings and create one but not provide me with the actual URLs. I was able to get all the Remote site IDs and do a call out to retrieve the data I wanted.