4

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.

1
  • Welcome to SFSE, Joelio.
    – Mike Chale
    Jul 19 '13 at 19:03
8

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.

2
  • 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. Jul 20 '13 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
    Jul 29 '15 at 17:59
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.