If I have a variable that I want to vary by environment, what is the best way to implement this in Salesforce?

For example, in dev I want to point to one external server, in test different one, and in production another.

  • Welcome to SFSE, Joelio.
    – Mike Chale
    Commented Jul 19, 2013 at 19:03

2 Answers 2


I would recommend using Custom Settings (read more at http://na1.salesforce.com/help/doc/en/cs_about.htm). They basically work as global variables for your orgs and can be set independently in production and in sandboxes.

Custom settings come in two flavors: a list and hierarchical. If you need to vary the setting by role or profile you would want to use the hierarchy option otherwise the list option is very straight-forward.

  • Agree with the above. Also handy is having a file, in your production environment, with the instructions on what steps need to be done after each sandbox refresh. Nothing like seeing QA traffic on your site analytics or burning thorough api limits because your test environment is still pointed at a production endpoint. Commented Jul 20, 2013 at 2:34
  • @Mike Chale - I noticed that Custom Settings don't get populated by default in a managed package (see the final note in this link). Does that mean for the example given, you would default to the production server and override that setting in test environments?
    – mralexlau
    Commented Jul 29, 2015 at 17:59

Custom Metadata types have an advantage over custom settings in that the values can be defined as metadata and migrated between instances.

I've created a Free/Open Source package that allows you to define "environmental variables" a as Key -> Value pairs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .