Why do I need to refresh my sandbox in a pipeline?
Sandboxes can be used in static environments in a Gearset pipeline and over time these sandboxes can drift out of sync with your production org.
The main goal of a sandbox refresh is to sync everything to be an exact copy of your production environment. It’s possible to pull all the data and metadata from the source org using a sandbox refresh, but each sandbox type will copy different areas of production. If the sandbox is a clone or using a sandbox template, the refresh process updates the org’s data and metadata.
Syncing up your sandboxes is vital to keeping your tests as reliable as possible. If your environments don’t match up, you could miss errors and bugs that could then make their way into production.
Before you start
Before you start your sandbox refresh, make sure you complete a sync of your environment branch with your main branch for the pipeline static environment your sandbox is part of.
This is so that when you come to sync the environment branch to the org after the sandbox refresh, you know that the environment branch isn't behind main in terms of commits. We have a doc here that has more details on how to complete this.
During the refresh
Salesforce limits the frequency of sandbox refreshes, more information on this frequency can be found here.
If you’re using the Salesforce refresh process to sync up your sandbox with your production org, it can take several days to complete – especially if you’re working with a full copy sandbox. During this time you won’t be able to access your sandbox and a window of downtime should be scheduled.
Pushing any changes through the pipeline static environment your sandbox is part of should be paused during the refresh.
This is because the sandbox is not accessible during the refresh window and the CI Job will error if changes are attempted to by pushed to the sandbox during this time.
After the refresh the sandbox may also be out of sync with your environment branch, depending on where and how the sandbox is used in your pipeline.
For more information on how to refresh your sandbox in salesforce, check out our blog post here
Following the refresh
Following the sandbox refresh, the sandbox may no longer be accessible from Gearset and you may need to re-authenticate the sandbox connection to Gearset. We have an article here on how to do this.
Depending on how your work with your sandbox in the pipeline, the in progress project changes that are in progress through the pipeline, that are not yet in your production org, will no longer be in the sandbox.
To sync these in progress changes, the sandbox will need to be synced with the git environment branch used by your static environment in the pipeline.
This can be completed using a compare and deploy in Gearset, with the environment branch as the source, and your refreshed sandbox org as the target.
The comparison should use the same metadata filter as is used for your CI Job on that pipeline static environment.
You should push any differences, relating to your in flight projects that have not yet reached production, from your environment branch to the sandbox to bring this back in sync.
Complete
Once this is completed you can start pushing changes through the static environment your sandbox is part of through your Gearset pipeline again.