Live Template: Assert Organization IsSandbox

Issue #2531 resolved
John Hanauer created an issue

One of my favorite live templates I’ve created for myself, that I think is worth adding to IC, is to assert the org I’m in is a sandbox. I use this when I start any new Anonymous Apex window because yes, like many, I sometimes play fast and loose with connecting IC directly to production orgs.

I use asb/sasb to insert either
Assert.isTrue([SELECT IsSandbox FROM Organization][0].IsSandbox);
System.assert([SELECT IsSandbox FROM Organization][0].IsSandbox);

I think bonus points if this could somehow be a setting to be inserted on every new Anonymous Apex tab by default. (Should I log another enhancement for that?)

Comments (6)

  1. Scott Wells repo owner

    John, are you familiar with the connection setting Require confirmation for all write operations? When set on a connection, IC2 will prompt you if you try to do anything that could modify the contents of that organization including, of course, metadata deployment/removal, but also Anonymous Apex execution. If you set that property on your production organization connections, you won’t need to remember to add such an assertion in your scripts.

  2. John Hanauer reporter

    Yes, and I absolutely enable Require confirmation for all write operations to all my PROD orgs. I think the live template still has several additional values. Off the top of my head, for one, adding the assertion to anonymous apex is a useful belt and suspenders approach that gives me peace of mind. Two, it allows me to pass off .apex files or copy-paste scripts and share with others that may not be using IC2 (also peace of mind). Three, there are Apex Classes that need to be deployed to production so that they’re replicated to future sandboxes, but the code should only run in sandboxes (like SandboxPostCopy and similar service classes). Obviously your call if you think other IC2 users would benefit from such a live template, but thankfully IntelliJ lets me create my own and I’ve done that.

  3. Scott Wells repo owner
    • changed status to open

    Okay, makes sense. Thanks for providing more context. I was concerned that you perhaps were not aware of that feature and were using these assertions as your one safeguard against making changes in your production (and other critical) orgs.

  4. Scott Wells repo owner

    Issue tracker grooming. I appreciate the contribution, but I'm inclined to keep the bundled live/postfix/file templates to those that are likely useful to the majority of IC2 users. This isn't the only such contribution, though, and there's no question of the value of these templates for some subset of IC2 users. I may look into a central place to add these things that is referenced by IC2 for those looking for existing templates that fill a need they might have.

  5. Log in to comment