I am integrating our back end systems with Salesforce using the web services. I have production and stage environments running on different URLs. I need to be able to have the endpoint of the web service call be different depending on whether the code is running in the production or sandbox Salesforce instance.
How do I detect the environment.
Currently I am considering looking up a user to see if there user name ends in 'devsandbox' as I have been unable to identify a system object that I can query to get the environment.
Further clarification:
The location I need to determine this is within the Apex code that is invoked when I select a button in Salesforce. My custom controller needs to know if it running in the production or sandbox Salesforce environment.
Navigate to the Trust site. Click the Status button next to status.salesforce.com. Paste your copied value into Search Instance, Domain, POD or MID. Click the magnifying glass icon to perform the search.
Look at your URL, if you log in at test.salesforce.com it's sandbox - and will bring you to csX.salesforce.com (x replaced with a number). While your production will log in at login.salesforce.com and bring you to naX.salesforce.com.
Types of Salesforce Environments: There are three types of Environments: Production Environments. Development Environments. Testing Environments.
Steps to find the sandbox type: Setup --> Deployment Settings --> continue -- > you will find the type of sandbox.
For y'all finding this via search results, there is an important update. As Daniel Hoechst pointed out in another post, SF now directly provides sandbox vs. production information:
In Summer '14, (version 31.0), there is a new field available on the Organization object.
select Id, IsSandbox from Organization limit 1
From the release notes under New and Change Objects:
The Organization object has the following new read-only fields.
InstanceName
IsSandbox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With