function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
eliotstock2eliotstock2 

determining the enviornment at runtime

Hi there.

 

I have a situation where I want to behave differently in Prod to the Sandbox. Is there anyway to tell programmatically which environment I'm executing in?

 

Thanks,

 

Eliot Stock.

BodhiDharmaBodhiDharma

As a best practice, code should not be dependent on the environment you are running in.  Orgs will change from time to time behind the scenes (e.g., you may find one day that your prod instance is no longer on na1 but is on na6).  There are many different ways to do common tasks without making it org-specific.  What are you trying to do? 

 

If you absolutely need to you could use {!$CurrentPage.Url} in a Visualforce page and extract the domain name.

 

eliotstock2eliotstock2
I was keen to avoid looking for na6 etc. in the URL. We have a PayPal integration piece that needs to use a test server in Sandbox and a production server in Prod. We already have the server URL in a record so I think I'll just cut the code that uses a different record depending on the environment out and change the data for one record in each environment.