plugin-templates
这个存储库为各种元数据类型提供了一系列命令、模板和生成器,包括对TypeScript闪电Web组件的支持。
开始使用
要使用,请安装 Salesforce CLI 并运行以下命令。
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]
安装
- 克隆存储库,然后
cd进去。
git clone [email protected]:salesforcecli/plugin-templates.git
- 确保你有 纱 安装并运行以下命令来构建:
yarn install
yarn build
问题
请将任何问题报告给 https://github.com/salesforcecli/plugin-templates/issues 或者 https://github.com/forcedotcom/cli/issues.
贡献
- 通过阅读文档和模板来熟悉代码库 图书馆.
- 如果要添加新的模板生成器,请参见 开发指南 详细说明。
- 在开始项目之前创建一个新问题,以便我们可以跟踪 你想要添加/修复的东西。这样,我们也可以提供建议或 让你知道是否已经有了进展。
- Fork这个存储库。
- 这个 构建 节详细介绍了如何设置您的环境。
- 创建一个 主题 基于正确的分支(通常是 主要 分支)。注意:这个步骤是推荐的,但是如果使用fork来贡献代码,从技术上来说不是必需的。
- 编辑您的分支中的代码。
- 签署CLA(参见 班)。
- 完成后给我们发个拉取请求。我们会检查你的代码,提出建议 需要更改,并将其合并。
把请求
提交
- 我们使用 commitizen。为了确保正确的格式,使用我们的VS Code任务
Commit。与yarn run commit. - 我们期望的提交消息格式是:
type: commit message。有效的类型是:壮举、修复、改进、文档、风格、重构、完善、测试、构建、ci、家务和恢复。 - 在提交和推送之前,Husky运行几个钩子,以确保提交消息的格式正确,并且所有内容都可以正确地检查和编译。
班
外部贡献者将被要求签署贡献者许可证 协议。你可以这样做,去 https://cla.salesforce.com/sign-cla.
构建
开发插件
要在本地测试插件,使用 bin/dev 代替 sfdx。例如:
./bin/dev force:apex:class:create --classname 'TestClass' --template 'DefaultApexClass' --outputdir ./testsoutput/myApex/
链接你的插件到Salesforce CLI:
sfdx plugins:link .
验证插件链接:
sfdx plugins
要使用Salesforce CLI在本地测试插件,请添加 "@salesforce/plugin-templates": "file://path/to/plugin-templates" 到插件的 package.json.
调试插件
我们建议使用Visual Studio Code (VS Code) IDE进行插件开发。包括在 .vscode 这个插件的目录是 launch.json 配置文件,该文件允许您在运行命令时将调试器附加到节点进程。
要调试 hello:org 命令:
- 如果您将插件链接到Salesforce CLI,则使用
dev-suspend开关:
$ sfdx hello:org -u [email protected] --dev-suspend
方法调用您的命令 bin/dev 脚本,设置 NODE_OPTIONS 环境变量to --inspect-brk 启动调试器时:
$ NODE_OPTIONS=--inspect-brk ./bin/dev force:apex:class:create --classname 'TestClass' --template 'DefaultApexClass' --outputdir ./testsoutput/myApex/
- 在命令代码中设置一些断点。
- 点击VS Code一侧的活动栏中的Debug图标,打开Debug视图。
- 在VS Code的左上角,确认选择了“Attach to Remote”启动配置。
- 点击“Attach to Remote”启动配置窗口左侧的绿色播放按钮。调试器现在应该挂起在程序的第一行。
- 点击VS Code中上方的绿色播放按钮(这个播放按钮位于你在步骤5中点击的播放按钮的右侧)。
祝贺你,你正在调试!
命令
sf template generate analytics templatesf template generate apex classsf template generate apex triggersf template generate digital-experience sitesf template generate flexipagesf template generate lightning-outsf template generate lightning appsf template generate lightning componentsf template generate lightning eventsf template generate lightning interfacesf template generate lightning testsf template generate projectsf template generate static-resourcesf template generate ui-bundlesf template generate ui-embeddingsf template generate visualforce componentsf template generate visualforce page
sf template generate analytics template
生成一个简单的Analytics模板。
USAGE
$ sf template generate analytics template -n <value> [--json] [--flags-dir <value>] [-d <value>] [--api-version
<value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the Analytics template.
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a simple Analytics template.
The metadata files associated with the Analytics template must be contained in a parent directory called
"waveTemplates" in your package directory. Either run this command from an existing directory of this name, or use the
--output-dir flag to generate one or point to an existing one.
ALIASES
$ sf force analytics template create
$ sf analytics generate template
EXAMPLES
Generate the metadata files for a simple Analytics template file called myTemplate in the
force-app/main/default/waveTemplates directory:
$ sf template generate analytics template --name myTemplate --output-dir force-app/main/default/waveTemplates
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
看代码: src /命令/模板/生成/分析/ template.ts
sf template generate apex class
生成一个Apex类。
USAGE
$ sf template generate apex class -n <value> [--json] [--flags-dir <value>] [-t
ApexException|ApexUnitTest|BasicUnitTest|Batchable|DefaultApexClass|InboundEmailService|Queueable] [-d <value>]
[--api-version <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated Apex class.
-t, --template=<option> [default: DefaultApexClass] Template to use for file creation.
<options: ApexException|ApexUnitTest|BasicUnitTest|Batchable|DefaultApexClass|InboundEmailS
ervice|Queueable>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate an Apex class.
Generates the Apex *.cls file and associated metadata file. These files must be contained in a parent directory called
"classes" in your package directory. Either run this command from an existing directory of this name, or use the
--output-dir flag to generate one or point to an existing one.
ALIASES
$ sf force apex class create
$ sf apex generate class
EXAMPLES
Generate two metadata files associated with the MyClass Apex class (MyClass.cls and MyClass.cls-meta.xml) in the
current directory:
$ sf template generate apex class --name MyClass
Similar to previous example, but generates the files in the "force-app/main/default/classes" directory:
$ sf template generate apex class --name MyClass --output-dir force-app/main/default/classes
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Apex class.
The name can be up to 40 characters and must start with a letter.
-t, --template=ApexException|ApexUnitTest|BasicUnitTest|Batchable|DefaultApexClass|InboundEmailService|Queueable
Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template.
看代码: src /命令/模板/生成/顶点/ class.ts
sf template generate apex trigger
生成一个Apex触发器。
USAGE
$ sf template generate apex trigger -n <value> [--json] [--flags-dir <value>] [-t ApexTrigger] [-d <value>] [--api-version
<value>] [-s <value>] [-e before insert|before update|before delete|after insert|after update|after delete|after
undelete...]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-e, --event=<option>... [default: before insert] Events that fire the trigger.
<options: before insert|before update|before delete|after insert|after update|after
delete|after undelete>
-n, --name=<value> (required) Name of the generated Apex trigger
-s, --sobject=<value> [default: SOBJECT] Salesforce object to generate a trigger on.
-t, --template=<option> [default: ApexTrigger] Template to use for file creation.
<options: ApexTrigger>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate an Apex trigger.
Generates the Apex trigger *.trigger file and associated metadata file. These files must be contained in a parent
directory called "triggers" in your package directory. Either run this command from an existing directory of this
name, or use the --output-dir flag to generate one or point to an existing one.
If you don't specify the --sobject flag, the .trigger file contains the generic placeholder SOBJECT; replace it with
the Salesforce object you want to generate a trigger for. If you don't specify --event, "before insert" is used.
ALIASES
$ sf force apex trigger create
$ sf apex generate trigger
EXAMPLES
Generate two files associated with the MyTrigger Apex trigger (MyTrigger.trigger and MyTrigger.trigger-meta.xml) in
the current directory:
$ sf template generate apex trigger --name MyTrigger
Similar to the previous example, but generate the files in the "force-app/main/default/triggers" directory:
$ sf template generate apex trigger --name MyTrigger --output-dir force-app/main/default/triggers
Generate files for a trigger that fires on the Account object before and after an insert:
$ sf template generate apex trigger --name MyTrigger --sobject Account --event "before insert,after insert"
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Apex trigger
The name can be up to 40 characters and must start with a letter.
-t, --template=ApexTrigger Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template.
看代码: src /命令/模板/生成/顶点/ trigger.ts
sf template generate digital-experience site
生成一个体验云站点。
USAGE
$ sf template generate digital-experience site -n <value> -t Build Your Own (LWR) [--json] [--flags-dir <value>] [-o <value>] [-p <value>]
[-e <value>] [-d <value>]
FLAGS
-d, --output-dir=<value> Directory to generate the site files in.
-e, --admin-email=<value> Email address for the site administrator. Defaults to the username of the currently
authenticated user.
-n, --name=<value> (required) Name of the Experience Cloud site to generate.
-o, --target-org=<value> Username or alias of the target org.
-p, --url-path-prefix=<value> URL path prefix for the site; must contain only alphanumeric characters.
-t, --template-name=<option> (required) Template to use when generating the site.
<options: Build Your Own (LWR)>
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate an Experience Cloud site.
Creates the metadata of an Experience Cloud site with the specified template, name, and URL path prefix. The output
includes all the necessary metadata files, including DigitalExperienceConfig, DigitalExperienceBundle, Network, and
CustomSite.
Unlike `sf community create`, which builds the site directly in the org, this command generates only the local
metadata.
EXAMPLES
Generate an Experience Cloud site using the Build Your Own (LWR) template. The site is called "mysite" and has the
URL path prefix "mysite":
$ sf template generate digital-experience site --template-name "Build Your Own (LWR)" --name mysite \
--url-path-prefix mysite
Generate an Experience Cloud site like the last example, but generate the files into the specified output directory:
$ sf template generate digital-experience site --template-name "Build Your Own (LWR)" --name mysite \
--url-path-prefix mysite --output-dir force-app/main/default
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory to generate the site files in.
The location can be an absolute path or relative to the current working directory. If not specified, the command
reads your sfdx-project.json file and uses the default package directory. When running outside a Salesforce DX
project, defaults to the current directory.
看代码: src /命令/模板/生成/数字体验/ site.ts
sf template generate flexipage
生成一个灵活页面,也称为闪电页面。
USAGE
$ sf template generate flexipage -n <value> -t RecordPage|AppPage|HomePage [--json] [--flags-dir <value>] [-d <value>]
[--api-version <value>] [--label <value>] [--description <value>] [-s <value>] [--primary-field <value>]
[--secondary-fields <value>...] [--detail-fields <value>...]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the FlexiPage.
-s, --sobject=<value> API name of the Salesforce object; required when creating a RecordPage.
-t, --template=<option> (required) Template type for the FlexiPage.
<options: RecordPage|AppPage|HomePage>
--api-version=<value> Override the api version used for api requests made by this command
--description=<value> Description for the FlexiPage, which provides context about its purpose.
--detail-fields=<value>... Fields to display in the Details tab. Specify multiple fields separated by commas.
Fields are split into two columns. Used only with RecordPage.
--label=<value> Label of this FlexiPage; if not specified, uses the FlexiPage name as the label.
--primary-field=<value> Primary field for the dynamic highlights header; typically 'Name'. Used only with
RecordPage.
--secondary-fields=<value>... Secondary fields shown in the dynamic highlights header. Specify multiple fields
separated by commas. Maximum of 11 fields. Used only with RecordPage.
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a FlexiPage, also known as a Lightning page.
FlexiPages are the metadata types associated with a Lightning page. A Lightning page represents a customizable screen
made up of regions containing Lightning components.
You can use this command to generate these types of FlexiPages; specify the type with the --template flag:
- AppPage: A Lightning page used as the home page for a custom app or a standalone application page.
- HomePage: A Lightning page used to override the Home page in Lightning Experience.
- RecordPage: A Lightning page used to override an object record page in Lightning Experience. Requires that you
specify the object name with the --sobject flag.
EXAMPLES
Generate a RecordPage FlexiPage for the Account object in the current directory:
$ sf template generate flexipage --name Account_Record_Page --template RecordPage --sobject Account
Generate an AppPage FlexiPage in the "force-app/main/default/flexipages" directory:
$ sf template generate flexipage --name Sales_Dashboard --template AppPage --output-dir \
force-app/main/default/flexipages
Generate a HomePage FlexiPage with a custom label:
$ sf template generate flexipage --name Custom_Home --template HomePage --label "Sales Home Page"
Generate a RecordPage with dynamic highlights and detail fields:
$ sf template generate flexipage --name Property_Page --template RecordPage --sobject Rental_Property__c \
--primary-field Name --secondary-fields Property_Address__c,City__c --detail-fields \
Name,Property_Address__c,City__c,Monthly_Rent__c,Bedrooms__c
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the FlexiPage.
The name can contain only alphanumeric characters, must start with a letter, and can't end with an underscore or
contain two consecutive underscores.
-s, --sobject=<value> API name of the Salesforce object; required when creating a RecordPage.
For RecordPage FlexiPages, you must specify the associated object API name, such as 'Account', 'Opportunity', or
'Custom_Object__c'. This sets the `sobjectType` field in the FlexiPage metadata.
看代码: src /命令/模板/生成/ flexipage / index.ts
sf template generate lightning-out
生成所需的元数据来支撑一个Lightning Out 2.0应用程序。
USAGE
$ sf template generate lightning-out [--json] [--flags-dir <value>] [--app-name <value>] [--eca-name <value>] [--runtime
LWR_CORE|CLWR] [--host-domains <value>...] [--components <value>...] [--eca-contact-email <value>]
[--eca-callback-url <value>] [--definition-file <value>] [-d <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
--app-name=<value> Developer name of the new Lightning Out 2.0 app.
--components=<value>... Name of a Lightning web component exposed by the app. Repeat the flag to specify more
than one. Replaces, rather than merges with, any components in the --definition-file.
--definition-file=<value> Path to a JSON file describing the Lightning Out 2.0 app. Individual flags, when
supplied, override the corresponding value in this file.
--eca-callback-url=<value> OAuth callback URL for the External Client Application.
--eca-contact-email=<value> Contact email for the External Client Application.
--eca-name=<value> Developer name of the External Client Application associated with the app.
--host-domains=<value>... HTTP or HTTPS origin of an external host page that embeds the app. Repeat the flag to
specify more than one. Replaces, rather than merges with, any hostDomains in the
--definition-file. For CLWR apps, host domains are used only for CORS, which
authenticated users need. Set up framing for the site in Experience Builder.
--runtime=<option> Runtime that serves the app.
<options: LWR_CORE|CLWR>
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate the required metadata to scaffold a Lightning Out 2.0 app.
Lightning Out 2.0 lets you embed custom Lightning web components (LWCs) into your external, non-Salesforce apps.
This command gets you started by generating the seven metadata artifact types that a Lightning Out 2.0 app requires
into your Salesforce DX project: LightningOutApp, MyDomain and Security settings, one CorsWhitelistOrigin per host
domain, and the three External Client Application OAuth components (ExternalClientApplication,
ExtlClntAppGlobalOauthSettings, ExtlClntAppOauthSettings). The command only generates files. It doesn't deploy any
metadata to an org.
Inputs can come from a --definition-file JSON, individual flags, or both. Flag values take precedence over the file on
a per-key basis. The command validates the types of definition-file fields; the underlying generator performs the
remaining structural validation, such as required fields and formats.
EXAMPLES
Generate a Lightning Out 2.0 app using individual flags to specify the values:
$ sf template generate lightning-out --app-name MyLoApp --runtime LWR_CORE --host-domains https://example.com \
--eca-name MyLoAppEca --eca-contact-email [email protected] --eca-callback-url https://example.com/cb
Generate an app using the values in a JSON definition file called lo-def.json:
$ sf template generate lightning-out --definition-file lo-def.json
Generate the app into a specific directory:
$ sf template generate lightning-out --definition-file lo-def.json --output-dir force-app/main/default
Generate a CLWR app for an Experience Cloud site using a definition file:
$ sf template generate lightning-out --runtime CLWR --definition-file lo-def.json
Generate the app using most of the values from a definition file, but the --host-domains value overrides its
equivalent in the file:
$ sf template generate lightning-out --definition-file lo-def.json --host-domains https://staging.example.com
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
--runtime=LWR_CORE|CLWR Runtime that serves the app.
LWR_CORE serves the app from your Salesforce org to authenticated users. CLWR serves it from an Experience Cloud
site to guest and authenticated users. After you deploy a CLWR app, link it to your site in Setup.
看代码: src /命令/模板/生成/ lightning-out / index.ts
sf template generate lightning app
生成一个闪电应用程序。
USAGE
$ sf template generate lightning app -n <value> [--json] [--flags-dir <value>] [-t DefaultLightningApp] [-d <value>] [--api-version
<value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated Lightning App.
-t, --template=<option> [default: DefaultLightningApp] Template to use for file creation.
<options: DefaultLightningApp>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Lightning App.
Generates a Lightning App bundle in the specified directory or the current working directory. The bundle consists of
multiple files in a folder with the designated name.
ALIASES
$ sf force lightning app create
$ sf lightning generate app
EXAMPLES
Generate the metadata files for a Lightning app bundle called "myapp" in the current directory:
$ sf template generate lightning app --name myapp
Similar to the previous example, but generate the files in the "force-app/main/default/aura" directory:
$ sf template generate lightning app --name myapp --output-dir force-app/main/default/aura
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Lightning App.
The name can be up to 40 characters and must start with a letter.
-t, --template=DefaultLightningApp Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template. For Lightning Web Components, if
this flag isn't specified, the CLI command automatically selects the template based on the "defaultLwcLanguage"
field in the DX project's "sfdx-project.json" file.
sf template generate lightning component
为Aura组件或Lightning web组件生成一个bundle。
USAGE
$ sf template generate lightning component -n <value> [--json] [--flags-dir <value>] [-t
default|analyticsDashboard|analyticsDashboardWithStep|typescript] [-d <value>] [--api-version <value>] [--type
aura|lwc]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated Lightning Component.
-t, --template=<option> [default: default] Template to use for file creation.
<options: default|analyticsDashboard|analyticsDashboardWithStep|typescript>
--api-version=<value> Override the api version used for api requests made by this command
--type=<option> [default: aura] Type of the component bundle.
<options: aura|lwc>
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a bundle for an Aura component or a Lightning web component.
Generates the bundle in the specified directory or the current working directory. The bundle consists of multiple
files in a directory with the designated name. Lightning web components are contained in the directory with name
"lwc", Aura components in "aura".
To generate a Lightning web component, pass "--type lwc" to the command. If you don’t specify --type, Salesforce CLI
generates an Aura component by default.
ALIASES
$ sf force lightning component create
$ sf lightning generate component
EXAMPLES
Generate the metadata files for an Aura component bundle in the current directory:
$ sf template generate lightning component --name mycomponent
Generate a Lightning web component bundle in the current directory:
$ sf template generate lightning component --name mycomponent --type lwc
Generate an Aura component bundle in the "force-app/main/default/aura" directory:
$ sf template generate lightning component --name mycomponent --output-dir force-app/main/default/aura
Generate a Lightning web component bundle in the "force-app/main/default/lwc" directory:
$ sf template generate lightning component --name mycomponent --type lwc --output-dir force-app/main/default/lwc
Generate a TypeScript Lightning Web Component:
$ sf template generate lightning component --name mycomponent --type lwc --template typescript
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Lightning Component.
The name can be up to 40 characters and must start with a letter.
-t, --template=default|analyticsDashboard|analyticsDashboardWithStep|typescript Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template. For Lightning Web Components, if
this flag isn't specified, the CLI command automatically selects the template based on the "defaultLwcLanguage"
field in the DX project's "sfdx-project.json" file.
看代码: src /命令/模板/生成/闪电/ component.ts
sf template generate lightning event
生成闪电事件。
USAGE
$ sf template generate lightning event -n <value> [--json] [--flags-dir <value>] [-t DefaultLightningEvt] [-d <value>] [--api-version
<value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated Lightning Event.
-t, --template=<option> [default: DefaultLightningEvt] Template to use for file creation.
<options: DefaultLightningEvt>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Lightning Event.
Generates a Lightning Event bundle in the specified directory or the current working directory. The bundle consists of
multiple files in a folder with the designated name.
ALIASES
$ sf force lightning event create
$ sf lightning generate event
EXAMPLES
Generate the metadata files for a Lightning event bundle called "myevent" in the current directory:
$ sf template generate lightning event --name myevent
Similar to previous example, but generate the files in the "force-app/main/default/aura" directory:
$ sf template generate lightning event --name myevent --output-dir force-app/main/default/aura
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Lightning Event.
The name can be up to 40 characters and must start with a letter.
-t, --template=DefaultLightningEvt Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template. For Lightning Web Components, if
this flag isn't specified, the CLI command automatically selects the template based on the "defaultLwcLanguage"
field in the DX project's "sfdx-project.json" file.
看代码: src /命令/模板/生成/闪电/ event.ts
sf template generate lightning interface
生成一个闪电接口。
USAGE
$ sf template generate lightning interface -n <value> [--json] [--flags-dir <value>] [-t DefaultLightningIntf] [-d <value>]
[--api-version <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated Lightning Interface.
-t, --template=<option> [default: DefaultLightningIntf] Template to use for file creation.
<options: DefaultLightningIntf>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Lightning Interface.
Generates a Lightning Interface bundle in the specified directory or the current working directory. The bundle
consists of multiple files in a folder with the designated name.
ALIASES
$ sf force lightning interface create
$ sf lightning generate interface
EXAMPLES
Generate the metadata files for a Lightning interface bundle called "myinterface" in the current directory:
$ sf template generate lightning interface --name myinterface
Similar to the previous example but generate the files in the "force-app/main/default/aura" directory:
$ sf template generate lightning interface --name myinterface --output-dir force-app/main/default/aura
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Lightning Interface.
The name can be up to 40 characters and must start with a letter.
-t, --template=DefaultLightningIntf Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template. For Lightning Web Components, if
this flag isn't specified, the CLI command automatically selects the template based on the "defaultLwcLanguage"
field in the DX project's "sfdx-project.json" file.
看代码: src /命令/模板/生成/闪电/ interface.ts
sf template generate lightning test
生成一个Lightning测试。
USAGE
$ sf template generate lightning test -n <value> [--json] [--flags-dir <value>] [-t DefaultLightningTest] [-d <value>]
[--api-version <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated Lightning Test.
-t, --template=<option> [default: DefaultLightningTest] Template to use for file creation.
<options: DefaultLightningTest>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Lightning test.
Generates the test in the specified directory or the current working directory. The .resource file and associated
metadata file are generated.
ALIASES
$ sf force lightning test create
$ sf lightning generate test
EXAMPLES
Generate the metadata files for the Lightning test called MyLightningTest in the current directory:
$ sf template generate lightning test --name MyLightningTest
Similar to the previous example but generate the files in the "force-app/main/default/lightningTests" directory:
$ sf template generate lightning test --name MyLightningTest --output-dir force-app/main/default/lightningTests
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Lightning Test.
Name of the new Lightning test; can be up to 40 characters and must start with a letter.
-t, --template=DefaultLightningTest Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template. For Lightning Web Components, if
this flag isn't specified, the CLI command automatically selects the template based on the "defaultLwcLanguage"
field in the DX project's "sfdx-project.json" file.
看代码: src /命令/模板/生成/闪电/ test.ts
sf template generate project
生成一个Salesforce DX项目。
USAGE
$ sf template generate project -n <value> [--json] [--flags-dir <value>] [-t
standard|empty|analytics|reactinternalapp|reactexternalapp|angularinternalapp|angularexternalapp|agent] [-d <value>]
[-s <value>] [-p <value>] [-x] [--lwc-language javascript|typescript] [--api-version <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated project.
-p, --default-package-dir=<value> [default: force-app] Default package directory name.
-s, --namespace=<value> Namespace associated with this project and any connected scratch orgs.
-t, --template=<option> [default: standard] Template to use for project creation.
<options: standard|empty|analytics|reactinternalapp|reactexternalapp|angularinterna
lapp|angularexternalapp|agent>
-x, --manifest Generate a manifest (package.xml) for change-set based development.
--api-version=<value> Will set this version as sourceApiVersion in the sfdx-project.json file
--lwc-language=<option> Language of the Lightning Web Components. If not specified, "javascript" is used.
<options: javascript|typescript>
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Salesforce DX project.
A Salesforce DX project has a specific structure and a configuration file (sfdx-project.json) that identifies the
directory as a Salesforce DX project. This command generates the necessary configuration files and directories to get
you started.
By default, the generated sfdx-project.json file sets the sourceApiVersion property to the default API version
currently used by Salesforce CLI. To specify a different version, set the apiVersion configuration variable. For
example: "sf config set apiVersion=57.0 --global".
ALIASES
$ sf force project create
$ sf project generate
EXAMPLES
Generate a project called "mywork":
$ sf template generate project --name mywork
Similar to previous example, but generate the files in a directory called "myapp":
$ sf template generate project --name mywork --default-package-dir myapp
Similar to prevoius example, but also generate a default package.xml manifest file:
$ sf template generate project --name mywork --default-package-dir myapp --manifest
Generate a project with the minimum files and directories:
$ sf template generate project --name mywork --template empty
Generate a project in which the Lightning Web Components use TypeScript rather than the default JavaScript:
$ sf template generate project --name mywork --lwc-language typescript
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated project.
Generates a project directory with this name; any valid directory name is accepted. Also sets the "name" property in
the sfdx-project.json file to this name.
-p, --default-package-dir=<value> Default package directory name.
Metadata items such as classes and Lightning bundles are placed inside this folder.
-t, --template=standard|empty|analytics|reactinternalapp|reactexternalapp|angularinternalapp|angularexternalapp|agent
Template to use for project creation.
The template determines the sample configuration files and directories that this command generates. For example, the
empty template provides these files and directory to get you started.
- .forceignore
- config/project-scratch-def.json
- sfdx-project.json
- package.json
- force-app (basic source directory structure)
The standard template provides a complete force-app directory structure so you know where to put your source. It
also provides additional files and scripts, especially useful when using Salesforce Extensions for VS Code. For
example:
- .gitignore: Use Git for version control.
- .prettierrc and .prettierignore: Use Prettier to format your Aura components.
- .vscode/extensions.json: When launched, Visual Studio Code, prompts you to install the recommended extensions for
your project.
- .vscode/launch.json: Configures Replay Debugger.
- .vscode/settings.json: Additional configuration settings.
The analytics template provides similar files and the force-app/main/default/waveTemplates directory.
The reactinternalapp and reactexternalapp templates provide React-based project scaffolding for internal and
external UI bundle use cases.
The angularinternalapp and angularexternalapp templates provide Angular-based project scaffolding for internal and
external UI bundle use cases.
The agent template provides project scaffolding for building Agentforce agents and includes a sample agent called
Local Info Agent.
-x, --manifest Generate a manifest (package.xml) for change-set based development.
Generates a default manifest (package.xml) for fetching Apex, Visualforce, Lightning components, and static
resources.
--api-version=<value> Will set this version as sourceApiVersion in the sfdx-project.json file
Override the api version used for api requests made by this command
--lwc-language=javascript|typescript Language of the Lightning Web Components. If not specified, "javascript" is used.
When set to `'typescript'`, generates TypeScript configuration files (tsconfig.json, package.json with TypeScript
dependencies, and TypeScript-aware ESLint config). When you deploy the TypeScript-based Lightning Web Components,
the TypeScript files are first compiled locally for validation and then the `.ts` files are deployed to your org for
server-side type stripping.
看代码: src /命令/模板/生成/项目/ index.ts
sf template generate static-resource
生成静态资源。
USAGE
$ sf template generate static-resource -n <value> [--json] [--flags-dir <value>] [--type <value>] [-d <value>]
[--api-version <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated static resource.
--api-version=<value> Override the api version used for api requests made by this command
--type=<value> [default: application/zip] Content type (mime type) of the generated static resource.
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a static resource.
Generates the metadata resource file in the specified directory or the current working directory. Static resource
files must be contained in a parent directory called "staticresources" in your package directory. Either run this
command from an existing directory of this name, or use the --output-dir flag to create one or point to an existing
one.
ALIASES
$ sf force staticresource create
$ sf static-resource generate
EXAMPLES
Generate the metadata file for a static resource called MyResource in the current directory:
$ sf template generate static-resource --name MyResource
Similar to previous example, but specifies a MIME type of application/json:
$ sf template generate static-resource --name MyResource --type application/json
Generate the resource file in the "force-app/main/default/staticresources" directory:
$ sf template generate static-resource --name MyResource --output-dir force-app/main/default/staticresources
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated static resource.
This name can contain only underscores and alphanumeric characters, and must be unique in your org. It must begin
with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.
--type=<value> Content type (mime type) of the generated static resource.
Must be a valid MIME type such as application/json, application/javascript, application/zip, text/plain, text/css,
etc.
看代码: src /命令/模板/生成/静态资源/ index.ts
sf template generate ui-bundle
生成一个UI包,其中包含代码和元数据,用于构建使用非原生Salesforce框架(如React或Angular)的UI体验。
USAGE
$ sf template generate ui-bundle -n <value> [--json] [--flags-dir <value>] [-t default|reactbasic|angularbasic|vuebasic] [-l
<value>] [-d <value>] [--api-version <value>]
FLAGS
-d, --output-dir=<value> Directory into which the files are created.
-l, --label=<value> Master label for the UI bundle.
-n, --name=<value> (required) API name of the generated UI bundle.
-t, --template=<option> [default: default] Template to use when creating the files for a specific UI framework.
<options: default|reactbasic|angularbasic|vuebasic>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a UI bundle, which contains the code and metadata to build a UI experience that uses non-native Salesforce
frameworks, such as React or Angular.
Salesforce provides native UI frameworks, such as Lighting Web Components (LWC), to build applications that run on the
Salesforce Platform. But you can also use non-native JavaScript- or TypeScript-based UI frameworks, such as React, to
build a UI experience for the Salesforce Platform and that you can launch from the App Launcher.
These non-native UI experiences are defined by the "UIBundle" metadata type in your DX project. Use this command to
generate the required DX project structure and files. For example, when you run this command and specify the name
MyUiBundle, then the files are generated into a "uiBundles/MyUiBundle" directory. Use the --output-dir flag to specify
a different directory.
Use the --template flag for generating the files to get started with a specific UI framework, such as React or
Angular. Check out the README.md file in the generated "uiBundles/<bundlename>" directory for more information about
the template.
EXAMPLES
Generate a UI bundle called MyUiBundle in the current directory:
$ sf template generate ui-bundle --name MyUiBundle
Generate a React-based UI bundle:
$ sf template generate ui-bundle --name MyReactApp --template reactbasic
Generate an Angular-based UI bundle:
$ sf template generate ui-bundle --name MyAngularApp --template angularbasic
Generate a Vue-based UI bundle:
$ sf template generate ui-bundle --name MyVueApp --template vuebasic
Generate the React-based UI bundle in the "force-app/main/default/uiBundles" directory:
$ sf template generate ui-bundle --name MyUiBundle --template reactbasic --output-dir \
force-app/main/default/uiBundles
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory into which the files are created.
The location can be an absolute path or relative to the current working directory.
If not specified, the command reads your sfdx-project.json and defaults to "uiBundles" directory within your default
package directory. When running outside a Salesforce DX project, defaults to the current directory.
**Important:** This command automatically ensures the output directory ends with "uiBundles". If your specified path
doesn't end with "uiBundles", it's automatically appended. The UI bundle is created at "<output-dir>/<name>".
**Examples:**
- "--output-dir force-app/main/default" → Creates a UI bundle at "force-app/main/default/uiBundles/MyUiBundle/"
- "--output-dir force-app/main/default/uiBundles" → Creates a UI bundle at
"force-app/main/default/uiBundles/MyUiBundle/" (no change)
-l, --label=<value> Master label for the UI bundle.
If not specified, the label is derived from the name.
-n, --name=<value> API name of the generated UI bundle.
This name can contain only underscores and alphanumeric characters, and must be unique in your org. It must begin
with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.
-t, --template=default|reactbasic|angularbasic|vuebasic
Template to use when creating the files for a specific UI framework.
Supplied parameter values or default values are filled into a copy of the template.
看代码: src /命令/模板/生成/ ui-bundle / index.ts
sf template generate ui-embedding
生成一个闪电Web组件(LWC)包来封装基本组件。
USAGE
$ sf template generate ui-embedding -n <value> -s <value> --sandbox
allow-forms|allow-modals|allow-orientation-lock|allow-pointer-lock|allow-popups|allow-popups-to-escape-sandbox|allow
-presentation|allow-same-origin|allow-scripts|allow-storage-access-by-user-activation|allow-top-navigation|allow-top
-navigation-by-user-activation... --title <value> [--json] [--flags-dir <value>] [-d <value>] [--api-version
<value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-n, --name=<value> (required) Name of the generated component; must be in PascalCase format.
-s, --src=<value> (required) Absolute HTTPS URL that the iframe will load.
--api-version=<value> Override the api version used for api requests made by this command
--sandbox=<option>... (required) Iframe sandbox token. Specify this flag multiple times to set more than one
token.
<options: allow-forms|allow-modals|allow-orientation-lock|allow-pointer-lock|allow-popups|a
llow-popups-to-escape-sandbox|allow-presentation|allow-same-origin|allow-scripts|allow-stor
age-access-by-user-activation|allow-top-navigation|allow-top-navigation-by-user-activation>
--title=<value> (required) Accessible title for the embedded iframe.
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Lightning Web Component (LWC) bundle that wraps the <lightning-ui-embedding> base component.
The generated LWC bundle consumes the first-party <lightning-ui-embedding> component, which is pre-wired with the
three required attributes: the embedding URL (--src), iframe sandbox tokens, and an accessible iframe title (--title).
The generated LWC bundle contains four files (.html, .js, .js-meta.xml, .css) in a directory named with the camelCased
component name. The bundle must live under a parent folder named "lwc".
EXAMPLES
Generate an embedding wrapper LWC in the current directory:
$ sf template generate ui-embedding --name MyEmbeddingWrapper --src https://app.example.com --sandbox \
allow-forms --title "Expense Report Embedding"
Generate an embedding wrapper LWC in the "force-app/main/default/lwc" directory with multiple sandbox tokens:
$ sf template generate ui-embedding --name MyEmbeddingWrapper --src https://app.example.com --sandbox \
allow-forms --sandbox allow-scripts --title "Expense Report Embedding" --output-dir force-app/main/default/lwc
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated component; must be in PascalCase format.
The component name is also used (camelCased) as the LWC folder name and file stem. Must contain only alphanumeric
characters and start with a letter.
-s, --src=<value> Absolute HTTPS URL that the iframe will load.
The URL is bound to the <lightning-ui-embedding> "src" attribute as a reactive property in the generated LWC. Must
use HTTPS; plain HTTP is allowed only for localhost or 127.0.0.1 (for local development).
--sandbox=allow-forms|allow-modals|allow-orientation-lock|allow-pointer-lock|allow-popups|allow-popups-to-escape-sandbox|allow-presentation|allow-same-origin|allow-scripts|allow-storage-access-by-user-activation|allow-top-navigation|allow-top-navigation-by-user-activation...
Iframe sandbox token. Specify this flag multiple times to set more than one token.
Each token is written into the space-separated "sandbox" attribute on <lightning-ui-embedding>. Only W3C-defined
sandbox tokens are accepted.
--title=<value> Accessible title for the embedded iframe.
Written to the "shell-title" attribute on <lightning-ui-embedding> and used as the iframe's accessible name
(announced by screen readers).
看代码: src /命令/模板/生成/嵌入/ index.ts
sf template generate visualforce component
生成Visualforce组件。
USAGE
$ sf template generate visualforce component -n <value> -l <value> [--json] [--flags-dir <value>] [-t DefaultVFComponent] [-d <value>]
[--api-version <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-l, --label=<value> (required) Visualforce Component label.
-n, --name=<value> (required) Name of the generated Visualforce Component.
-t, --template=<option> [default: DefaultVFComponent] Template to use for file creation.
<options: DefaultVFComponent>
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Visualforce Component.
The command generates the .Component file and associated metadata file in the specified directory or the current
working directory by default.
ALIASES
$ sf force visualforce component create
$ sf visualforce generate component
EXAMPLES
Generate the metadata files for a Visualforce component in the current directory:
$ sf template generate visualforce component --name mycomponent --label mylabel
Similar to previous example, but generate the files in the directory "force-app/main/default/components":
$ sf template generate visualforce component --name mycomponent --label mylabel --output-dir components
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Visualforce Component.
The name can be up to 40 characters and must start with a letter.
-t, --template=DefaultVFComponent Template to use for file creation.
Supplied parameter values or default values are filled into a copy of the template.
看代码: src /命令/模板/生成/ visualforce / component.ts
sf template generate visualforce page
生成Visualforce页面。
USAGE
$ sf template generate visualforce page -n <value> -l <value> [--json] [--flags-dir <value>] [-d <value>]
[--api-version <value>]
FLAGS
-d, --output-dir=<value> [default: .] Directory for saving the created files.
-l, --label=<value> (required) Visualforce Page label.
-n, --name=<value> (required) Name of the generated Visualforce Page.
--api-version=<value> Override the api version used for api requests made by this command
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
--json Format output as json.
DESCRIPTION
Generate a Visualforce Page.
The command generates the .Page file and associated metadata file in the specified directory or the current working
directory by default.
ALIASES
$ sf force visualforce page create
$ sf visualforce generate page
EXAMPLES
Generate the metadata files for a Visualforce page in the current directory:
$ sf template generate visualforce page --name mypage --label mylabel
Similar to previous example, but generate the files in the directory "force-app/main/default/pages":
$ sf template generate visualforce page --name mypage --label mylabel --output-dir pages
FLAG DESCRIPTIONS
-d, --output-dir=<value> Directory for saving the created files.
The location can be an absolute path or relative to the current working directory. The default is the current
directory.
-n, --name=<value> Name of the generated Visualforce Page.
The name can be up to 40 characters and must start with a letter.