generate Commands
generate function
Description for generate function
Both '--language' and '--name' are required flags. Function names must start with a capital letter.
Examples for generate function
Create a JavaScript function:
Usage
- sf generate function
- [--json]
- [-n FUNCTION-NAME]
- -l LANGUAGE
Flags
- --json
- Optional
-
Format output as json.
- Type: boolean
- -n | --function-name FUNCTION-NAME
- Optional
-
Function name. Must start with a capital letter.
- Type: option
- -l | --language LANGUAGE
- Required
-
The language in which the function is written.
- Type: option
- Permissible values are: java, javascript, typescript
generate metadata field (Beta)
Description for generate metadata field
This command is interactive and must be run in a Salesforce DX project directory. You're required to specify the field's label with the "--label" flag. The command uses this label to provide intelligent suggestions for other field properties, such as its API name.
You can generate a custom field on either a standard object, such as Account, or a custom object. In both cases, the source files for the object must already exist in your local project before you run this command. If you create a relationship field, the source files for the parent object must also exist in your local directory. Use the command "sf metadata retrieve -m CustomObject:<object>" to retrieve source files for both standard and custom objects from your org. To create a custom object, run the "sf generate metadata sobject" command or use the Object Manager UI in your Salesforce org.
Examples for generate metadata field
Create a field with the specified label; the command prompts you for the object:
Specify the local path to the object's folder:
Usage
- sf generate metadata field
- [--json]
- -l LABEL
- [-o OBJECT]
Flags
- --json
- Optional
-
Format output as json.
- Type: boolean
- -l | --label LABEL
- Required
-
The field's label.
- Type: option
- -o | --object OBJECT
- Optional
-
The directory that contains the object's source files.
The object source files in your local project are grouped in a directoy with the same name as the object. Custom object names always end in "__c". An example of the object directory for the Account standard object is "force-app/main/default/objects/Account" An example custom object directory is "force-app/main/default/objects/MyObject__c"
If you don't specify this flag, the command prompts you to choose from your local objects.
- Type: option
generate metadata platformevent (Beta)
Description for generate metadata platformevent
This command is interactive and must be run in a Salesforce DX project directory. You're required to specify the event's label with the "--label" flag. The command uses this label to provide intelligent suggestions for other event properties, such as its API name.
Examples for generate metadata platformevent
Create a platform event with the specified label:
Usage
- sf generate metadata platformevent
- [--json]
- -l LABEL
Flags
- --json
- Optional
-
Format output as json.
- Type: boolean
- -l | --label LABEL
- Required
-
The platform event's label.
- Type: option
generate metadata sobject (Beta)
Description for generate metadata sobject
This command is interactive and must be run in a Salesforce DX project directory. You're required to specify the object's label with the "--label" flag. The command uses this label to provide intelligent suggestions for other object properties, such as its API name and plural label.
All Salesforce objects are required to have a Name field, so this command also prompts you for the label and type of the Name field. Run the "sf metadata generate field" command to create additional fields for the object.
To reduce the number of prompts, use the "--use-default-features" flag to automatically enable some features, such as reporting and search on the object.
Examples for generate metadata sobject
Create a custom object with the specified label and be prompted for additional information:
Create a custom object and enable optional features without prompting:
Usage
- sf generate metadata sobject
- [--json]
- -l LABEL
- [-f]
Flags
- --json
- Optional
-
Format output as json.
- Type: boolean
- -l | --label LABEL
- Required
-
The custom object's label.
- Type: option
- -f | --use-default-features
- Optional
-
Enable all optional features without prompting.
Enables these features:
* Search: Allows users to find the custom object's records when they search, including SOSL.
* Feeds: Enables feed tracking.
* Reports: Allows reporting of the data in the custom object records.
* History: Enables object history tracking.
* Activities: Allows users to associate tasks and scheduled calendar events related to the custom object records.
* Bulk API: With Sharing and Streaming API, classifies the custom object as an Enterprise Application object.
* Sharing: With Bulk API and Streaming API, classifies the custom object as an Enterprise Application object.
* Streaming API: With Bulk API and Sharing, classifies the custom object as an Enterprise Application object.
- Type: boolean
generate metadata tab (Beta)
Description for generate metadata tab
Custom tabs let you display custom object data or other web content in Salesforce. Custom tabs appear in Salesforce as an item in the app’s navigation bar and in the App Launcher.
This command must be run in a Salesforce DX project directory. You must pass all required information to it with the required flags. The source files for the custom object for which you're generating a tab don't need to exist in your local project.
Examples for generate metadata tab
Create a tab on the MyObject__c custom object:
Usage
- sf generate metadata tab
- [--json]
- -o OBJECT
- -d DIRECTORY
- -i ICON
Flags
- --json
- Optional
-
Format output as json.
- Type: boolean
- -o | --object OBJECT
- Required
-
API name of the custom object you're generating a tab for.
The API name for a custom object always ends in "__c", such as "MyObject__c".
- Type: option
- -d | --directory DIRECTORY
- Required
-
Path to a "tabs" directory that will contain the source files for your new tab.
- Type: option
- -i | --icon ICON
- Required
-
Number from 1 to 100 that specifies the color scheme and icon for the custom tab.
See https://lightningdesignsystem.com/icons/\#custom for the available icons.
- Type: option
- Default value: 1
generate project
Description for generate 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 basic scaffolding 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:
Examples for generate project
Generate a project called MyProject:
Generate the minimum number of files and directories:
Generate the project in /Users/jdoe/sf-projects rather than the current directory:
Usage
- sf generate project
- [--json]
- [-p DEFAULT-PACKAGE-DIR]
- [-x]
- -n NAME
- [-s NAMESPACE]
- [-d OUTPUT-DIR]
- [-t TEMPLATE]
Flags
- --json
- Optional
-
Format output as json.
- Type: boolean
- -p | --default-package-dir DEFAULT-PACKAGE-DIR
- Optional
-
Default package directory name.
The default package directory name. Metadata items such as classes and Lightning bundles are placed inside this folder.
- Type: option
- Default value: force-app
- -x | --manifest
- Optional
-
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.
- Type: boolean
- -n | --name NAME
- Required
-
Name of the generated project.
Creates a project directory with this name. Also sets the "name" property in the sfdx-project.json file to this name.
- Type: option
- -s | --namespace NAMESPACE
- Optional
-
Project associated namespace.
The namespace associated with this project and any connected scratch orgs.
- Type: option
- -d | --output-dir OUTPUT-DIR
- Optional
-
Directory to store the newly created project files.
The location can be an absolute path or relative to the current working directory.
- Type: option
- Default value: .
- -t | --template TEMPLATE
- Optional
-
Template to use to create the project.
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.
- Type: option
- Permissible values are: standard, empty, analytics
- Default value: standard