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

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 – [email protected].sandboxname

production – [email protected]

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

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

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.

You may also like

Leave a Comment