DEV Community

Cover image for SFDX Good to know - Pull, Push and Deploy (PART 2)
Luke Secomb
Luke Secomb

Posted on

SFDX Good to know - Pull, Push and Deploy (PART 2)

If you don't know what a Scratch Org, a DevHub or an SFDX Project are you must have missed Part 1, go check that out before moving on.

Okay, so you've got your Orgs and Hubs set up, now let's move some code around.

Fetch / Pull Data

Fetching data from an org is super simple. Replace COMPONENTS_I_NEED with a comma-separated list of items to retrieve.

sfdx force:source:retrieve -m COMPONENTS_I_NEED -u ALIAS_FOR_YOUR_DEV_HUB

The following command is an example of retrieving all ApexClasses, ApexPages and LightningComponentBundles (LWC).

sfdx force:source:retrieve -m ApexClass, ApexPage, LightningComponentBundle -u ALIAS_FOR_YOUR_DEV_HUB

Need a hand figuring out what you need to pull? Check out the Metadata Ref


Deploy code back to DevHub

Alright, now you've retrieved your components and made some edits, now its time to deploy your code to the scratch org we set up in part 1.

Similarly to how we retrieved data, we can define what we want to deploy in the same way.

Below is an example of deploying those same components we retrieved before.

sfdx force:source:deploy -m ApexPage, ApexClasses, LightningComponentBundle -u ALIAS_FOR_YOUR_DEV_HUB

Only want to push a component or two? No problem, just pass the -p flag (instead of -m) and the path your component

sfdx force:source:deploy -p force-app/main/default/lwc/SINGLE_COMPONENT_NAME -u ALIAS_FOR_YOUR_DEV_HUB

This doesn't have to be an LWC, it can be any file (ApexClass, GlobalPicklist, ApexTrigger etc.)

Didn't see the Metadata Ref link before? Here it is again Metadata Ref

Discussion (0)