plugin-templates
This repository provides a series of commands, templates, and generators for various metadata types.
Getting Started
To use, install the Salesforce CLI and run the following commands.
Verify the CLI is installed
$ sfdx (-v | --version)
Install the @salesforce/plugin-templates plugin
$ sfdx plugins:install @salesforce/plugin-templates
To run a command
$ sfdx [command]
Install
- Clone the repository, and
cd
into it.
git clone git@github.com:salesforcecli/plugin-templates.git
- Ensure you have Yarn installed and run the following to build:
yarn install
yarn build
Issues
Please report any issues to https://github.com/salesforcecli/plugin-templates/issues or https://github.com/forcedotcom/cli/issues.
Contributing
- Familiarize yourself with the codebase by reading the docs and the templates library.
- Create a new issue before starting your project so that we can keep track of what you're trying to add/fix. That way, we can also offer suggestions or let you know if there is already an effort in progress.
- Fork this repository.
- The build section has details on how to set up your environment.
- Create a topic branch in your fork based on the correct branch (usually the main branch). Note: this step is recommended but technically not required if contributing using a fork.
- Edit the code in your fork.
- Sign CLA (see CLA).
- Send us a pull request when you're done. We'll review your code, suggest any needed changes, and merge it in.
Pull Requests
Committing
- We enforce commit message format using commitizen. To ensure correct formatting, use our VS Code Task
Commit
. withyarn run commit
. - The commit message format that we expect is:
type: commit message
. Valid types are: feat, fix, improvement, docs, style, refactor, perf, test, build, ci, chore and revert. - Before commit and push, Husky runs several hooks to ensure the commit message is in the correct format and that everything lints and compiles properly.
CLA
External contributors will be required to sign a Contributor's License Agreement. You can do so by going to https://cla.salesforce.com/sign-cla.
Build
Developing Plugin
To test plugin locally, use bin/dev
in place of sfdx
. For example:
./bin/dev force:apex:class:create --classname 'TestClass' --template 'DefaultApexClass' --outputdir ./testsoutput/myApex/
Link your plugin to Salesforce CLI:
sfdx plugins:link .
Verify plugin is linked:
sfdx plugins
To test plugin locally with Salesforce CLI, add "@salesforce/plugin-templates": "file://path/to/plugin-templates"
to the plugin's package.json
.
Debugging Your Plugin
We recommend using the Visual Studio Code (VS Code) IDE for your plugin development. Included in the .vscode
directory of this plugin is a launch.json
config file, which allows you to attach a debugger to the node process when running your commands.
To debug the hello:org
command:
- If you linked your plugin to the Salesforce CLI, call your command with the
dev-suspend
switch:
$ sfdx hello:org -u myOrg@example.com --dev-suspend
Alternatively, to call your command using the bin/dev
script, set the NODE_OPTIONS
environment variable to --inspect-brk
when starting the debugger:
$ NODE_OPTIONS=--inspect-brk ./bin/dev force:apex:class:create --classname 'TestClass' --template 'DefaultApexClass' --outputdir ./testsoutput/myApex/
- Set some breakpoints in your command code.
- Click on the Debug icon in the Activity Bar on the side of VS Code to open up the Debug view.
- In the upper left hand corner of VS Code, verify that the "Attach to Remote" launch configuration is selected.
- Hit the green play button to the left of the "Attach to Remote" launch configuration window. The debugger should now be suspended on the first line of the program.
- Hit the green play button at the top middle of VS Code (this play button is to the right of the play button that you clicked in step #5).
Congrats, you are debugging!
Commands
A list of the available commands
sfdx force:apex:class:create
create an Apex class
USAGE
$ sfdx force:apex:class:create -n <string> [-d <string>] [-t <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-n, --classname=classname(required) name of the generated Apex class
-t, --template=ApexException|ApexUnitTest|DefaultApexClass|InboundEmailService [default: DefaultApexClass] template
to use for file creation
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
EXAMPLES
$ sfdx force:apex:class:create -n MyClass
$ sfdx force:apex:class:create -n MyClass -d classes
See code: src/commands/force/apex/class/create.ts
sfdx force:apex:trigger:create
create an Apex trigger
USAGE
$ sfdx force:apex:trigger:create -n <string> [-d <string>] [-e <string>] [-s <string>] [-t <string>] [--apiversion
<string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-e, --triggerevents=before insert|before update|before delete|after insert|after update|after delete|after undelete
[default: before insert] events that fire the trigger
-n, --triggername=triggername (required) name of the generated Apex trigger
-s, --sobject=sobject [default: SOBJECT] sObject to create a trigger on
-t, --template=ApexTrigger [default: ApexTrigger] template to use for file creation
--apiversion=apiversion override the api version used for api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for this command invocation
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
EXAMPLES
$ sfdx force:apex:trigger:create -n MyTrigger
$ sfdx force:apex:trigger:create -n MyTrigger -s Account -e 'before insert, after upsert'
$ sfdx force:apex:trigger:create -n MyTrigger -d triggers
See code: src/commands/force/apex/trigger/create.ts
sfdx force:lightning:app:create
create a Lightning app
USAGE
$ sfdx force:lightning:app:create -n <string> [-d <string>] [-t <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-n, --appname=appname (required) name of the generated
Lightning app
-t, --template=DefaultLightningApp [default: DefaultLightningApp]
template to use for file creation
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your
bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we
create force-app/myBundle/ to store the files in the bundle.
EXAMPLES
$ sfdx force:lightning:app:create -n myapp
$ sfdx force:lightning:app:create -n myapp -d aura
See code: src/commands/force/lightning/app/create.ts
sfdx force:lightning:component:create
create a bundle for an Aura component or a Lightning web component
USAGE
$ sfdx force:lightning:component:create -n <string> [-d <string>] [-t <string>] [--type <string>] [--apiversion
<string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-n, --componentname=componentname (required) name of the generated
Lightning component
-t, --template= [default: DefaultLightningCmp]
template to use for file creation
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
--type=aura|lwc [default: aura] type of the
Lightning component
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your
bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we
create force-app/myBundle/ to store the files in the bundle.
To create a Lightning web component, pass --type lwc to the command. If you don’t include a --type value, Salesforce
CLI creates an Aura component by default.
EXAMPLES
$ sfdx force:lightning:component:create -n mycomponent
$ sfdx force:lightning:component:create -n mycomponent --type lwc
$ sfdx force:lightning:component:create -n mycomponent -d aura
$ sfdx force:lightning:component:create -n mycomponent --type lwc -d lwc
See code: src/commands/force/lightning/component/create.ts
sfdx force:lightning:event:create
create a Lightning event
USAGE
$ sfdx force:lightning:event:create -n <string> [-d <string>] [-t <string>] [--apiversion <string>] [--json]
[--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-n, --eventname=eventname (required) name of the generated
Lightning event
-t, --template=DefaultLightningEvt [default: DefaultLightningEvt]
template to use for file creation
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your
bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we
create force-app/myBundle/ to store the files in the bundle.
EXAMPLES
$ sfdx force:lightning:app:create -n myevent
$ sfdx force:lightning:event:create -n myevent -d aura
See code: src/commands/force/lightning/event/create.ts
sfdx force:lightning:interface:create
create a Lightning interface
USAGE
$ sfdx force:lightning:interface:create -n <string> [-d <string>] [-t <string>] [--apiversion <string>] [--json]
[--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-n, --interfacename=interfacename (required) name of the generated
Lightning interface
-t, --template=DefaultLightningIntf [default: DefaultLightningIntf]
template to use for file creation
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your
bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we
create force-app/myBundle/ to store the files in the bundle.
EXAMPLES
$ sfdx force:lightning:interface:create -n myinterface
$ sfdx force:lightning:interface:create -n myinterface -d aura
See code: src/commands/force/lightning/interface/create.ts
sfdx force:lightning:test:create
create a Lightning test
USAGE
$ sfdx force:lightning:test:create -n <string> [-d <string>] [-t <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-n, --testname=testname (required) name of the generated Lightning test
-t, --template=DefaultLightningTest [default: DefaultLightningTest] template to use for file creation
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for this command invocation
DESCRIPTION
The outputdir can be an absolute path or relative to the current working directory.
EXAMPLES
$ sfdx force:lightning:test:create -n MyLightningTest
$ sfdx force:lightning:test:create -n MyLightningTest -d lightningTests
See code: src/commands/force/lightning/test/create.ts
sfdx force:project:create
create a Salesforce DX project
USAGE
$ sfdx force:project:create -n <string> [-d <string>] [-p <string>] [-s <string>] [-t <string>] [-x] [--json]
[--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-n, --projectname=projectname (required) name of the generated
project
-p, --defaultpackagedir=defaultpackagedir [default: force-app] default package
directory name
-s, --namespace=namespace project associated namespace
-t, --template=standard|empty|analytics [default: standard] template to use
for file creation
-x, --manifest generate a manifest (package.xml)
for change-set based development
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
DESCRIPTION
Default values are used if the template, namespace, defaultpackagedir, and outputdir aren’t supplied.
The outputdir can be an absolute path or relative to the current working directory.
EXAMPLES
$ sfdx force:project:create --projectname mywork
$ sfdx force:project:create --projectname mywork --defaultpackagedir myapp
$ sfdx force:project:create --projectname mywork --defaultpackagedir myapp --manifest
$ sfdx force:project:create --projectname mywork --template empty
See code: src/commands/force/project/create.ts
sfdx force:visualforce:component:create
create a Visualforce component
USAGE
$ sfdx force:visualforce:component:create -n <string> -l <string> [-d <string>] [-t <string>] [--apiversion <string>]
[--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-l, --label=label (required) Visualforce component
label
-n, --componentname=componentname (required) name of the generated
Visualforce component
-t, --template=DefaultVFComponent [default: DefaultVFComponent]
template to use for file creation
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
The outputdir can be an absolute path or relative to the current working directory.
Name and label are required.
EXAMPLES
$ sfdx force:visualforce:component:create -n mycomponent -l mylabel
$ sfdx force:visualforce:component:create -n mycomponent -l mylabel -d components
See code: src/commands/force/visualforce/component/create.ts
sfdx force:visualforce:page:create
create a Visualforce page
USAGE
$ sfdx force:visualforce:page:create -n <string> -l <string> [-d <string>] [-t <string>] [--apiversion <string>]
[--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-d, --outputdir=outputdir folder for saving the created files
-l, --label=label (required) Visualforce page label
-n, --pagename=pagename (required) name of the generated
Visualforce page
-t, --template=DefaultVFPage [default: DefaultVFPage] template to
use for file creation
--apiversion=apiversion override the api version used for
api requests made by this command
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
this command invocation
DESCRIPTION
If not supplied, the apiversion, template, and outputdir use default values.
If not supplied, the apiversion, template, and outputdir use default values.
Name and label are required.
EXAMPLES
$ sfdx force:visualforce:page:create -n mypage -l mylabel
$ sfdx force:visualforce:page:create -n mypage -l mylabel -d pages