7

Could you tell me what would be the value of IsSandbox if I specify the following class during sandbox creation? Will it be 'true' or 'fasle'?

global class HelloWorld implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {
     Organization org = [SELECT IsSandbox FROM Organization];
     // if(org.IsSandbox) {} ?
    }
}
7
  • 5
    Is this a Dev II Exam question? – crmprogdev Jun 7 '16 at 12:01
  • @C0DEPirate It does in fact return true. Had to run it myself just to check. – martin Jun 7 '16 at 13:16
  • @martin You are right, I also just tested it. Deleted my comment – C0DEPirate Jun 7 '16 at 13:18
  • @C0DEPirate You were right though. It does return true. – martin Jun 7 '16 at 14:26
  • @C0DEPirate I refreshed a sandbox. – martin Jun 7 '16 at 14:38
6

The query will return true for Organization.IsSandbox when this code is run as part of a sandbox refresh.

I ran the following class:

global class SandboxRefreshClass implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {
      insert new Account(name = 'Context Org Id: ' + context.organizationId() + ' Context Sandbox Id: ' + context.sandboxId());
      insert new Account(name = ' UserInfo Session Id:  ' + UserInfo.getSessionId() + ' UserInfo Org Id:  ' + UserInfo.getOrganizationId());
      insert new Account(name = ' Organization IsSandbox: ' + [SELECT IsSandbox FROM Organization].IsSandbox);
    }
}

And got the following results:

Context Org Id: /* 15 digit sandbox org id */ Context Sandbox Id: /* 15 digit sandbox id (07E not 00D)*/

UserInfo Session Id: null UserInfo Org Id: /* 18 digit sandbox org id */

Organization IsSandbox: true

2
  • 2
    I see if my refresh script is dependent on UserInfo.getSessionId() I'm screwed. – mardok Jun 8 '16 at 8:00
  • @mardok Unfortunately that seems to be the case for now. – martin Jun 8 '16 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.