6

I have a webservice class that will be in a managed package and distributed to multiple clients. The class currently has a variable with the hardcoded value of the server it's hitting.

The problem: the server will be different for each client, so a hardcoded value will not work.

I figured since each client will have to add their server to their remote site settings, the easiest way might be to grab the correct URL from their setting. Is this possible? Or is there another "right" way to accomplish this? Thanks

CDelaney
  • 1,238
  • 4
  • 19
  • 36

1 Answers1

10

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 Butler
  • 2,733
  • 23
  • 27
  • How about if all I want to do is test to see if the remote-site setting exists? – tggagne Nov 16 '11 at 15:25
  • I just want to test (inside a unit test) to see if the remote site is properly configured. After deploying to production (or integration) I want to test multiple setup parameters, one of them being if the remote site setting has been created correctly. – tggagne Nov 16 '11 at 15:31
  • 3
    I'm not aware of any way to access remote site settings setup from within Apex code. You could write a method which attempts a callout to a given URL, then if Salesforce suppresses the callout (catch the exception) you'll know that the Remote site setting is not setup correctly – Adam Butler Nov 16 '11 at 18:00
  • But Metadta APi by itself requires an endpoint set in Remote Site Setting . How will you overcome that requirement ? @Adam – Keerthan Tantry Jan 24 '14 at 04:33