I'm currently managing my code in git.

We are about to refresh all sandboxes, so all changes that aren't in production will be deleted.

However, they are in git. Therefore, git is more updated than the sandbox.

What is the process when refreshing a sandbox? What should i do in order to put all code from git to the sandbox?

Do i first retrieve the org, and only then push the changes from git to the sandbox?

  • I assume your metadata isn't part of a (managed) package. In which case, you should be able to simply use sfdx to push or deploy (depending on whether you have mdapi or source structure in git) all your metadata from your git workspace to the sandbox. – Phil W Feb 24 '20 at 11:14
  • @PhilW I only want to deploy the code, not the metadata – Dana Griff Feb 24 '20 at 11:52
  • If you are using mdapi you can configure the package.xml to include only classes and triggers, for example. If you are using sfdx you can use .forceignore to ignore everything except classes and triggers, for example. – Phil W Feb 24 '20 at 12:49

There are multiple ways to move code from GIT to sandbox (also,production)...

Firstly, are you using ANT or SFDX?

Either way, recommend you to clone one of your sandbox just for backup in case of repercussions: https://help.salesforce.com/articleView?id=data_sandbox_cloning_overview.htm&type=5

Using ANT:

  1. Create a Meta-data structured folder with all the components to be deployed to the sandbox...
  2. Deploy to the sandbox as usual: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_deploying_ant.htm

Using SfDX: (Relatively Easy)

  1. Create a blank Manifest project on VS Code and authorize your
    sandbox. (Alternatively, you can use: sfdx force:auth:web:login -d -a ) https://developer.salesforce.com/tools/vscode/en/user-guide/development-models/#create-project-with-manifest

  2. Clone your remote repository locally using git clone.

  3. execute sfdx force:source:push

Switch/change your sandbox linked in step 1 and repeat steps 2 and 3 to deploy more

  • I would not recommend using Ant any more - sfdx can do everything needed here. Also, not everyone uses VS Code. – Phil W Feb 24 '20 at 12:51
  • Alternatively, the command can be used without VS code :), Agreed about ANT 😀 – Abhijith E Feb 24 '20 at 13:01

I'd do this using sfdx. Exactly how depends on whether you are using metadata API structure or source structure in your project in git.

  1. Get a clone of your git repository so you have a workspace
  2. Authorize access to your sandbox for the SFDX CLI (sfdx force:auth:web:login)
  3. Set up a package.xml that only lists classes and triggers to deploy (using "*" wildcard for each)
  4. Use either sfdx force:mdapi:deploy or sfdx force:source:deploy with the package.xml to push the data to the sandbox, depending on the structure you have in git (mdapi if classes/triggers/etc are not in a "force-app/default/main" type sub-folder)

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.