2

I am facing an issue, where I accidentally corrupted my local SFDX repository. But fortunately, I have already pushed the changes to the SFDX scratch org. Now the issue is my scratch org has the actual good code, but on my local machine the code is corrupted, and I can't pull it back from the scratch org instance.

when I do

sfdx force:source:pull -f

It says no results found.

Similarly to check the syncing I moved a class out of the local repository, and did the pull command, with the expectation that SF will detect the missing class file and generate a copy from the scratch org. None of this happened.

Please help.

  • I'm not sure what you trying to do is possible with SFDX. When you run sfdx force:source:pull it will only bring the differences (changes you have done manually since your last push) to the org. If you have lost your meta-data which you push to the org, may be setup a password for your scratch org user and use an IDE like eclipse (FORCE.COM IDE) to pull specific meta down. OR you could use ant tool if you are familiar with it. – Ranga Jun 25 '18 at 19:02
  • Are you using VCS? Git, SVN, etc. – pchittum Jun 26 '18 at 14:25
2

DX is still a work in progress; it's production quality but definitely has some known limitations. I do recall that this limitation is one that the DX team is looking to address, but that's not a current feature, so we can't depend on that.

This basically happens today because Salesforce doesn't do a full sync when pulling, but only tracks things that have changed on the server since the last push. Since there are no changes, it won't pull anything. In the future, a cleaner alternative might become available (hopefully sooner than later!).

Hopefully, you already have a package you can use in your scratch org to pull everything back down? If you do, it's pretty much as simple as:

sfdx force:mdapi:retrieve -p "Some Package" -d . -u userNameOrAlias
unzip unpackaged
sfdx force:mdapi:convert -r "Some Package"

This assumes you have a project configuration file, want to use the default path, and just looking to put everything back in order. You'll have to do some clean up and diffs afterwards, but at least you'll be back in sync.

Otherwise, if you don't have a package, you'll have to build one, or a manual package.xml file to download everything you want. If you do that, the force:mdapi:retrieve command uses -k name-of-package.xml instead of the -p "Package Name" format.

  • Thank you @sfdcfox. I did the same, by creating a user in the scratch org, and pulling all the org metadata from there. Then used a comparison tool to fix my corrupted changes. – Shridhar Puntambekar Jun 25 '18 at 20:47
1

I think the best way is to

  1. Back up your project folder (zip it, version it)
  2. Get yourself a package.xml file that describes what you want pulled
  3. Run the retrieve command
  4. Run the mdapi convert command
  5. Unzip the package and delete the zip file
  6. Finally, deploy back to your scratch org again (it's the same code that you just pulled, but back in sfdx format)

Retrieve:

sfdx force:mdapi:retrieve -s -r ./mdapipkg -u <your username> -k ./src/package.xml 

Convert:

sfdx force:source:convert -d mdapipkg/

Deploy:

sfdx force:mdapi:deploy -d mdapipkg/ -u <yoursboxalias> -w 100

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.