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
    Commented Jun 7, 2016 at 12:01
  • @C0DEPirate It does in fact return true. Had to run it myself just to check.
    – martin
    Commented Jun 7, 2016 at 13:16
  • @martin You are right, I also just tested it. Deleted my comment
    – C0DEPirate
    Commented Jun 7, 2016 at 13:18
  • @C0DEPirate You were right though. It does return true.
    – martin
    Commented Jun 7, 2016 at 14:26
  • @C0DEPirate I refreshed a sandbox.
    – martin
    Commented Jun 7, 2016 at 14:38

1 Answer 1

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
    Commented Jun 8, 2016 at 8:00
  • @mardok Unfortunately that seems to be the case for now.
    – martin
    Commented Jun 8, 2016 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .