Determine if the Salesforce instance is production org or a Sandbox org in code?
Most efficient way of identifying the type of org (Production or Sandbox) via Apex code: Actually we can query this detail from Organization object as below: On the top of this, we can build our own service method like below: