2

Scratch org: how to retrieve metadata

I am probably missing some concepts, but this are the steps that I have follow to create a new scratch org from a developer edition org.

Created a new dev org In setup >> Dev Hub >> I enabled Enable Dev Hub and Enable Unlocked Packages (GA) and Second-Generation Managed Packages (Beta) From VS, I created a new project with manifest (authorize it, add alias, ...) From VS, I created a new scratch org, with an alias "firstattempt", this generated this success message:

11:14:07.787 sfdx force:org:create -f config\project-scratch-def.json --setalias firstattempt --durationdays 7 --setdefaultusername
Successfully created scratch org: 00Dp00000009ccFEAQ, username: test-ovvqjhrqkdcl@example.com
11:14:24.478 sfdx force:org:create -f config\project-scratch-def.json --setalias firstattempt --durationdays 7 --setdefaultusername ended with exit code 0

So this is where I am confused.

If I want to develop in this scracth org, I guess I need to create another project in VS?

I created a new project in VS, and set the default org to be the new alias created when the scracth org was created.

(I tested opening the default org and it opens in a new tab without having to authorize) enter image description here

The problem is that I dont have an option to retrieve metadata

So I am guessing I need to authorize this new project?

But if I do this I will need to put the username and password in the web browser, and when the scratch org was created I only get a username, is there a way to authorize the org without doing this web auth?

Or I am doing something wrong and I dont need to create a new project when working with the scratch orgs?

3

A scratch org is a completely blank Salesforce org that's divorced from the Dev Hub or any other org you have in the Salesforce universe. So there's no metadata to retrieve from the scratch org itself.

If you want to pull metadata from a different org, like the Dev Hub org or a Production / Sandbox org, into your scratch org, do the following:

  1. First authorize the org you'd like to retrieve metadata from:
sfdx force:auth:web:login -a MyDevOrg
  1. Use force:source:retrieve to pull relevant metadata you're looking for from that org. See the documentation on all the options of how to pull specific metadata. A sample of how to pull all classes and triggers will look something like this:
sfdx force:source:retrieve -m ApexTrigger,ApexClass -u MyDevOrg 
  1. Push that metadata you just retrieved from your local project into your scratch org
sfdx force:source:push
  • Thank you Brian, I am a bit more confused now, I thought the puropse of the scratch org was to develop in it (create code) and once I am happy with the development then push this code to a different org, but I think u understood to do the opposite? code where the scratch org was "born: and then push this into the scratch org? – manza Apr 4 at 4:23
  • 1
    This deserves a whole post, but on one foot - development happens on your local machine in a DX project. From there, you have two main options - 1) push/pull/develop against the scratch org, which keeps source control, compiles code/settings in the exact environment setup on the scratch org; 2) push/pull/develop against a sandbox, much like the process that people know from MavensMate; (or 3 - both together). Scratch orgs has inherent source control and mirrors git, but you can achieve that paradigm just connecting your DX project to Github and do development in a sandbox – Brian Miller Apr 4 at 6:41

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.