Forcecmd
A command-line tool for the Salesforce metadata API
Install / Use
/learn @jesperkristensen/ForcecmdREADME
Command line tool for the Salesforce metadata API
This command line tool allows you to use the file based Salesforce metadata API
to download and deploy your Org's configuration and code.
The tool will automatically build the required package.xml file for you
and work around some bugs and limitations in the metadata API.
Installation
- Install Node.js from http://nodejs.org/.
- Open a command prompt / terminal.
- Run
npm install --global forcecmd.
Set up an org
-
Create an empty directory for your org.
-
Create a new file in your org's directory named
forcecmd.jsonwith content like this:{ "hostname": "login.salesforce.com", "username": "yourname@yourcompany.com" } -
Create a new file in your home directory (
~) namedforcepw.jsonwith content like this:{ "passwords": { "login.salesforce.com:yourname@yourcompany.com": "YourPasswordYourSecirityToken" } }
Download an org
- Navigate your command prompt to your org's directory.
- Type
forcecmd retrieve.
All metadata and all custom settings are downloaded by default. You can customize this in forcecmd.json like this:
{
"apiVersion": "45.0",
"hostname": "login.salesforce.com",
"username": "yourname@yourcompany.com",
"excludeDirs": ["documents"],
"objects": {
"MyCustomSetting__c": false,
"Product2": true,
"Pricebook2": ["Id", "Name", "IsActive"],
"PricebookEntry": "select Product2Id, Pricebook2Id, UnitPrice from PricebookEntry where IsActive = true"
}
}
Use forcecmd retrieve --verbose to see what values are available to customize, or to debug issues finding the right password.
Upon completion the tool will typically print a number of messages from the Metadata API indicating problems. This is normal. If the status is Succeeded, you can ignore the messages.
Deploy changes
- Navigate your command prompt to our org's directory.
- Type for example
forcecmd deploy src/classes/MyClass.cls src/objects/Account.object.
Additional arguments:
--destroy: Delete all the listed files instead of updating them.'--options={"rollbackOnError":true}': Specify deployment options as documented on http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_deploy.htm#deploy_options--save-test-result: Save test results (if tests are run) to a file namedTEST-result.xmlin JUnit format.--ignore-deploy-errors: By default the process exits with an error code when the deployment fails. Use this argument to always exit with success no matter if the deployment was successful or not.--timed: Show timestamps next to log messages.
Use with continous integration
You can use forcecmd together with a continuous integration tool and a version control system to backup and track changes to all your Salesforce organization's customizations (metadata), and to continously run all your Salesforce organization's unit tests.
See an example of how to set this up completely in the cloud using GitHub.
See an example of how to set this up completely in the cloud using Azure DevOps.
Developing forcecmd
To set up development environment:
- Clone this repository.
- From the root of the cloned repository, run
npm install. - Replace
forcecmdwithnode path/to/this/tool/cli.jswhen you use the tool.
License
MIT
Related Skills
walmart-sales-analyzer
Analyze Walmart sales data to explore trends between store sales and unemployment rates. Generate insightful visualizations and a beautiful HTML report with deep analysis. Suitable for quick insights into the relationship between sales data and macroeconomic factors.
ditto-sales-enablement
2Claude Code skill: Generate a complete sales enablement kit (battlecard, objection guide, quote bank, one-pager, pitch narrative, ROI framework, demo script) from a single Ditto research study.
dubbl
3A full-featured, open-source alternative to Xero and QuickBooks. It is API-first, developer-friendly, and built for teams that want full control over their financial data.
heroku-agentforce-mcp
3This repository has 4 different MCP projects that demonstrates some of the inner workings of the MCP and architectural patterns when integrating with various Agents as well as Agentforce.
