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
CodeFinderCodeFinder 

Code that finds difference between sandbox and production environment.

Hi,

 

I have an external wsdl which has been parsed into apex classes. There is an endpoint to it and the end point is different for production and sandbox. The sandbox should point out to sandbox endpoint of the external wsdl and the production points out to the production wsdl endpoint. Is there any way so that i can write a code which can help me in detecting the environment  so that the code determines if the environment is sandbox then endpoint points to the sandbox wsdl.

Best Answer chosen by Admin (Salesforce Developers) 
neophyteneophyte

You can save the organisation id for your production org in a custom setting/custom label (get the organisation id from Company profile -> Company Information). Now in your code compare the org in which the org is runnung (UserInfo.getOrganizationId) to the prod org id.

 

example:

If(UserInfo.getOrganizationId() ==  Label.production_org_id)

 

if true: the org is production

if false: org is a sandbox

 

Anand

All Answers

neophyteneophyte

You can save the organisation id for your production org in a custom setting/custom label (get the organisation id from Company profile -> Company Information). Now in your code compare the org in which the org is runnung (UserInfo.getOrganizationId) to the prod org id.

 

example:

If(UserInfo.getOrganizationId() ==  Label.production_org_id)

 

if true: the org is production

if false: org is a sandbox

 

Anand

This was selected as the best answer
SFFSFF

Here's some code I've used to figure out whether I'm on a sandbox or production:

 

http://www.salesforcefast.com/2012/07/what-type-of-salesforce-org-am-i.html

 

Good luck!