hardis:project:clean:orgmissingitems
Description
Command Behavior
Cleans Salesforce DX project sources by removing metadata components that are not present in a target Salesforce org or the local package.xml file.
This command helps maintain a lean and accurate codebase by identifying and removing metadata that is either obsolete in the target org or not explicitly included in your project's package.xml. This is particularly useful for:
- Reducing Deployment Size: Eliminating unnecessary metadata reduces the size of deployments, leading to faster deployments and fewer conflicts.
- Ensuring Consistency: Synchronizing your local codebase with the actual state of a Salesforce org.
- Cleaning Up Orphaned Metadata: Removing components that might have been deleted from the org but still exist in your local project.
Key features:
- Target Org Integration: Connects to a specified Salesforce org (or prompts for one) to retrieve its metadata manifest.
package.xmlComparison: Compares your local project's metadata with the target org's metadata and your localpackage.xmlto identify missing items.- Report Type Cleaning: Specifically targets and cleans
reportType-meta.xmlfiles by removing references to fields or objects that are not present in the target org or yourpackage.xml.
Technical explanations
The command's technical implementation involves several steps:
- Org Manifest Generation: If not provided, it generates a full
package.xmlfrom the target Salesforce org usingbuildOrgManifest. - XML Parsing and Merging: It parses the generated org manifest and merges it with the local
package.xmlanddestructiveChanges.xmlfiles to create a comprehensive list of existing and deleted metadata. - Metadata Analysis: It iterates through specific metadata types (currently
reportType-meta.xmlfiles) within the configured source folder. - Field and Object Validation: For each
reportType-meta.xmlfile, it examines the columns and filters out references to custom fields or objects that are not found in the mergedpackage.xmlcontent or are marked for destruction. - XML Modification: If changes are detected, it updates the
reportType-meta.xmlfile by writing the modified XML content back to the file usingwriteXmlFile. - File System Operations: It uses Node.js
fsfor file system operations andglobfor pattern matching to find relevant metadata files. - SOQL Queries: The
buildOrgManifestutility (used internally) performs SOQL queries to retrieve metadata information from the Salesforce org.
Agent Mode
Supports non-interactive execution with --agent:
sf hardis:project:clean:orgmissingitems --agent --packagexmltargetorg myorg@example.com
In agent mode:
- The interactive org prompt is skipped;
--packagexmltargetorgor--packagexmlfullflag is required. - If neither flag is provided, an error is thrown.
Screenshots
Pick the org that the sources are compared with
The items that the target org does not have are removed from the project sources
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 | Root folder | force-app | ||
| json | boolean | Format output as json. | |||
| packagexmlfull -p |
option | Path to packagexml used for cleaning. Must contain also standard CustomObject and CustomField elements. If not provided, it will be generated from a remote org |
|||
| packagexmltargetorg -t |
option | Target org username or alias to build package.xml (SF CLI must be authenticated). If not provided, will be prompted to the user. |
|||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:project:clean:orgmissingitems
$ sf hardis:project:clean:orgmissingitems --agent

