When you come to metadata deployment model, usually, you’ll be working following this process:
- Implement your feature on the DEV org
- Retrieve the corresponding metadatas
- Store the metadatas in GIT
- Deploy the metadata in UAT, PREPROD, PROD…
Easy. But when it comes to retrieve metadatas by command lines, it sometimes becomes a nightmare because you don’t know exactly what to retrieve or with which exact command…
I propose here to give you the command lines and tips I use!
Don’t hesitate to bookmark the page, I’ll add other commands in the future since I use them very often.
Retrieve Metadatas using SFDX
Retrieve everything from org according to Manifest
This command is usefull to retrieve everything that is declared in your manifest file. It can take some time to run 😉
sfdx force:source:retrieve -x manifest/package.xml --verbose
Retrieve object definition
Retrieve an Object (custom or not) definition. Note that everything comes: field, object definition, actions…
sfdx force:source:retrieve -m CustomObject:OBJECT_API_NAME__c
Retrieve field definition
This is more precise than the previous command and will retrieve you only the mentioned field
sfdx force:source:retrieve -m CustomField:Object.Field
Retrieve layout
Retrieve of a page layout
sfdx force:source:retrieve -m "Layout:NAME_OF_OBJECT-NAME_OF_LAYOUT"
Retrieve Label
Note that the labels are all stored in the same file.
sfdx force:source:retrieve -m CustomLabels:CUSTOM_LABEL_NAME
Retrieve Flow
Retrieve a Flow with its identifier. Please note that retrieving a process builder works with the same command.
sfdx force:source:retrieve -m Flow:FLOW_IDENTIFIER
Retrieve VisualForce
Retrieve a VF Page
sfdx force:source:retrieve -m ApexPage:PAGE_NAME
Retrieve Email template
To retrieve an Email template, do not forget to precise the Folder Name
sfdx force:source:retrieve -m "EmailTemplate:FOLDER/Template_unique_name"
Retrieve list of files
If you already an SFDX project and you want to update your local files with the corresponding metadata on the org, this command is for you:
sfdx force:source:retrieve -p "path/to/file1,path/to/file2,path/to/file3”
Retrieve Global Value set (global picklist)
Retrieve the Global Value (picklists shared values).
Note that when created with a value Set, it’s not possible to move a picklist from a global value set to another.
sfdx force:source:retrieve -m GlobalValueSet:NAME_OF_GLOBAL_SET
Retrieve Tab (belonging to object)
sfdx force:source:retrieve -m CustomTab:MY_OBJECT__c
Retrieve Validation rules
sfdx force:source:retrieve -m ValidationRule:OBJECT__c.MY_SUPER_VALIDATION_RULE
Retrieve Action (New/Edit Button override)
If you need to retrieve Standard action override, you need to retrieve the Object definition file
Retrieve Lightning page
sfdx force:source:retrieve -m FlexiPage:NAME_OF_PAGE
Retrieve Email alert
sfdx force:source:retrieve -m WorkflowAlert:Object__c.Email_Alert_Name
Retrieve Lightning App
sfdx force:source:retrieve -m "CustomApplication:My_Super_App_API_NAME"
Retrieve Image of the application
sfdx force:source:retrieve -m "ContentAsset:the_id_of_logo_to_find_in_app_XML"
Retrieve Custom Metadata values
sfdx force:source:retrieve -m CustomMetadata:MetadataTypeAPIName.MetadataRecordAPIName
Retrieve Weblink
sfdx force:source:retrieve -m "Weblink:Object__c.Name"
Retrieve Commerce Cloud Settings : enabled
This command, trust me, is quite hard to find. It allows to enable the Commerce Cloud, which is very usefull if it’s not already activated in the target org you’re deploying in (otherwise, you’ll hit some errors of unknow objects for example)
sfdx force:source:retrieve -m Settings:Commerce
Retrieve the metadata from VS Code
It’s far, far easier that retrieving from command lines.
In VS Code, in the left toolbar, click on the cloud
And… tada! You can see that you can retrieve nearly everything you want: Apex Triggers, Apex Classes…
Open the metadatas categories and click to download the metadata you need