how to identify the logged in salesforce org either sandbox or production

This blog post to describe about to identiy the salesforce org type either sandbox or production.

we have multiple workaround inorder to identify the salesforce org type and here is few ways:

1. use the formula field to user object to identify the username level (mostly username value in sandbox and production different) –

for ex: sandbox – sakthivel@theblogreaders.com.sandboxname

production – sakthivel@theblogreaders.com

2. use apex class to identify the logged in salesforce org either sandbox or production

private static Boolean runningInASandbox() {
return [SELECT Id, IsSandbox FROM Organization LIMIT 1].IsSandbox;
}

3. use SOQL to identify the logged in salesforce org either sandbox or production, currently Organization object have the IsSandbox field to identify the Salesforce Org type

SELECT Id, IsSandbox, Name FROM Organization

some reference links:

Determine sandbox name vs production from apex – https://success.salesforce.com/ideaView?id=0873000000083sJAAQ

https://salesforce.stackexchange.com/questions/200508/formula-field-distinguish-between-prod-and-full-copy-sandbox

https://salesforce.stackexchange.com/questions/120400/differentiate-production-sandbox-instance

Share if you have any other approach to idenity the Salesforce org either sandbox or Production.

Written by 

Salesforce MVP | 15x Salesforce Certified | Lightning Champion | Application Architect | 6x Trailhead Ranger | Sydney | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*