Wednesday, January 1, 2025

Execute Apex code over Sandbox environment only, but have it on production as we

Execute Apex code over Sandbox environment only, but have it on production as well 🔥 🔥
public Class Helloword
{
public void runlogicOnSandboxOnly()
{
Boolean isSandbox = IsrunningInASandbox();
if (isSandbox)
{
// code for Sandbox only
}
}
public Boolean IsrunningInASandbox() {
return [SELECT Id, IsSandbox FROM Organization LIMIT 1].IsSandbox;
}
}