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 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

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

*