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
anil rathoureanil rathoure 

How we will know that user has been logged in sandbox or production through Apex ?

Best Answer chosen by anil rathoure
Prem Anandh 1Prem Anandh 1
Hi Anil, 

Please run below code 
[SELECT Id, IsSandbox FROM Organization LIMIT 1].IsSandbox;

if IsSandbox is return true, it's Sandbox else it's production/developer environment. 

Thanks,
Prem Anandh

All Answers

Prem Anandh 1Prem Anandh 1
Hi Anil, 

Please run below code 
[SELECT Id, IsSandbox FROM Organization LIMIT 1].IsSandbox;

if IsSandbox is return true, it's Sandbox else it's production/developer environment. 

Thanks,
Prem Anandh
This was selected as the best answer
Prem Anandh 1Prem Anandh 1
Hi Anil, 
Make sure your Apex Class Version should be 31.0 or above
anil rathoureanil rathoure
Thank you