0

I need to create new scratch orgs every 30 days (because they expire every 30 days) but on my project there is a big number of post-steps to configure the scratch org which take enormous amount of time

Is there a way to extend the scratch org above 30 days or to create a new sandbox from the scratch org which could live more than 30 days?

Or is there a way to create a copy of scratch org? (which could have the same code and which could also contain other changes which can't be stored as metadata)

2
  • Are you using org shape to create the scratch org: help.salesforce.com/s/… Commented Aug 3, 2022 at 16:15
  • What sort of post-creation steps are you having to do? Commented Aug 3, 2022 at 19:17

3 Answers 3

1

No, no, and no.

Scratch orgs are purposefully time-limited, and sandboxes can only be created and managed from a paid (production) org.

It sounds to me like you're mis-using scratch orgs here, like you're trying to force a square peg through a round hole. In my mind, scratch orgs are mostly meant for things like quick demonstrations and single projects that don't have any (or many) dependencies.

Needing to go through a laborious setup process each time doesn't sound like an independent (or single) project. I think that you should be using a developer sandbox instead of a scratch org.

  • Sandboxes are not time-limited
  • You can make a template for sandboxes (which may or may not reduce the amount of configuration you need to do, only available to use in partial copy and full copy sandboxes)
  • Developer Sandboxes can be refreshed daily, if needed (though you'd need to go through your setup after refreshing a sandbox)
  • Sandboxes allow you to specify an Apex class to be run after the refresh

You might be able to get away with using sfdx force:data:tree:import, but again, this really doesn't sound like a scratch org is appropriate in your situation.

2
  • 1
    For an ISV use of scratch orgs is really important for package development. They are not just for demos and "single projects that don't have (m)any dependencies". Using a scratch org allows us to be sure that only the metadata from specific versions of dependencies and from our git repo is on the org. We use them for almost all our development as one scratch org per work item - the only case where we use the same one for more than one work item is when working on extension packages where just installing the dependencies takes an hour... we still stick to scratch orgs though. Commented Aug 3, 2022 at 20:26
  • 1
    I would stick with scratch orgs and wait until scratch org snapshots are available... Commented Aug 3, 2022 at 20:37
1

The answer to all of these questions is no. Setting up a scratch org can almost always be fully automated, including loading metadata, data, and various settings. If it takes more than, say, 30 minutes or so, to spin up a scratch org, you're probably better off just using Sandboxes. Enable the new Source Tracking for Sandboxes feature, and you can use Sandboxes with all the upsides of Scratch Orgs, without the downside of a 30-day time limit. You can clone any Sandbox from any other Sandbox, but you cannot clone Scratch Orgs from a Sandbox or a Sandbox from a Scratch Org.

1
  • 1
    "All the upsides" fails to consider that installing a dependency via upgrade is not the same as installing fresh. Not all packagable metadata is upgradeable (e.g. page layouts, field inline help etc.) so you can find you are developing on an org where the dependency packages diverge from expectation. Commented Aug 3, 2022 at 20:34
0

The other answers are both correct in pointing out that using scratch orgs requires you to think a bit differently about how you handle environments. As sfdcfox said, it's absolutely possible to automate everything that goes into a scratch org.

You're encountering a long time guiding principle of mine... Seaver's Law of Software Engineering:

Persistence means always having to say you're sorry

That wasn't created specifically for Salesforce but is rooted in similar concepts. If you are developing code that relies on declarative configuration in an instance that's not automated in version control, the mismatch in state due to lack of automation will always come back to bite you.

I used scratch orgs for years before I had the realization that "scratch" isn't intended to mean a scratch piece of paper you doodle ideas on. It's best thought of a "starting from scratch". Using scratch orgs effectively requires investing in automating the entire process of setting up a fully usable org. The value of scratch orgs is that you can start everything you do from scratch and test the entire process of delivering your product. The predictability and scalability is well worth the effort to create the needed automation.

We ran all our dev orgs as 7 day scratch orgs by default. Whenever someone came to me requesting a longer duration, I saw that as a red flag pointing to tech debt of missing automation to create a usable environment. It was absolutely the exception for us to create 30 day scratch orgs.

In my time at Salesforce.org, we developed a new model for development called the Product Delivery Model. The Product Delivery Model defines a product as a set of automation configurations in version control that can be run through a portable pipeline to deliver fully usable product experiences into an org. Automation is part of the product, not an afterthought and missing automation is treated as tech debt.

Ultimately, it comes down to a simple question. What is the source of truth for your product? Is it an org or is it version control? In order for it to be version control, you have to have everything defined in version control including all the post-install steps you do manually today.

I'm incredibly excited about Scratch Org Snapshots for what they can do to enhance a development process that properly uses scratch orgs as ephemeral environments to start from scratch to test your ability to deliver a product. Yet, I'm quite frightened that snapshots will become a shortcut that teams use to avoid properly investing in automation. Snapshots come from an org. If you did any manual setup in that org, then that org is your source of truth rather than version control.

As for how to actually do this, there are many options ranging from using sfdx and bash scripts to using automation frameworks such as CumulusCI (disclaimer: I used to lead the team that built CumulusCI at Salesforce.org but am really trying to keep this answer about concepts vs tools).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.