hardis:org:retrieve:sources:metadata
Description
Command Behavior
Retrieves Salesforce metadata from an org into a local directory, primarily for backup and monitoring purposes.
This command is designed to pull metadata from any Salesforce org, providing a snapshot of its configuration. It's particularly useful in monitoring contexts where you need to track changes in an org's metadata over time.
Key functionalities:
- Metadata Retrieval: Connects to a target Salesforce org and retrieves metadata based on a specified
package.xml. - Managed Package Filtering: By default, it filters out metadata from managed packages to reduce the volume of retrieved data. This can be overridden with the
--includemanagedflag. - Monitoring Integration: Designed to be used within a monitoring CI/CD job, it performs additional post-retrieval actions like running Apex tests and checking for legacy API usage.
Technical explanations
The command's technical implementation involves:
- Git Repository Check: Ensures the current directory is a Git repository and initializes it if necessary.
MetadataUtils.retrieveMetadatas: This utility is the core of the retrieval process. It connects to the Salesforce org, retrieves metadata based on the providedpackage.xmland filtering options (e.g.,filterManagedItems), and places the retrieved files in a specified folder.- File System Operations: Uses Node.js
fsto manage directories and copy retrieved files to the target folder. - Post-Retrieval Actions (for Monitoring Jobs): If the command detects it's running within a monitoring CI/CD job (
isMonitoringJob()):- It updates the
.gitlab-ci.ymlfile ifAUTO_UPDATE_GITLAB_CI_YMLis set. - It converts the retrieved metadata into SFDX format using
sf project convert mdapi. - It executes
sf hardis:org:test:apexto run Apex tests. - It executes
sf hardis:org:diagnose:legacyapito check for legacy API usage. - It logs warnings if post-actions fail or if the monitoring version is deprecated.
- It updates the
- Error Handling: Includes robust error handling for retrieval failures and post-action execution.
Agent Mode
Supports non-interactive execution with --agent:
sf hardis:org:retrieve:sources:metadata --agent
In agent mode, all interactive prompts are skipped and default values are used.
Screenshots
Every metadata of the Helios org retrieved in Metadata API format, managed package items left out
- (1) Items of managed packages are not retrieved
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| agent | boolean | Run in non-interactive mode for agents and automation | |||
| debug -d |
boolean | Activate debug mode (more logs) | |||
| flags-dir | option | Import flag values from a directory. | |||
| folder -f |
option | Folder | . | ||
| includemanaged | boolean | Include items from managed packages | |||
| instanceurl -r |
option | URL of org instance | |||
| json | boolean | Format output as json. | |||
| packagexml -p |
option | Path to package.xml manifest file | |||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| target-org -o |
option | Username or alias of the target org. Not required if the target-org configuration variable is already set. |
true | ||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:org:retrieve:sources:metadata
$ sf hardis:org:retrieve:sources:metadata --agent
$ SFDX_RETRIEVE_WAIT_MINUTES=200 sf hardis:org:retrieve:sources:metadata
