Newer Version Available

This content describes an older version of this product. View Latest

Development

After you import some test data, you’ve completed the process of setting up your project. Now, you’re ready to start the development process.

Create Source Files from the CLI

To add source files from the CLI, make sure that you’re working in an appropriate directory. For example, if your package directory is called force-app, create Apex classes in force-app/main/default/classes. You can organize your source as you want underneath each package directory except for documents, custom objects, and custom object translations.

As of API version 45.0, you can build Lightning components using two programming models: Lightning Web Components and Aura Components. To organize your components’ source files, your Aura components must be in the aura directory. Your Lightning web components must be in the lwc directory.

Execute one of these commands.

  • apex generate class
  • apex generate trigger
  • cmdt generate object
  • cmdt generate field
  • cmdt generate record
  • cmdt generate records
  • cmdt generate fromorg
  • lightning generate app
  • lightning generate component
  • lightning generate event
  • lightning generate interface
  • lightning generate test
  • schema generate sobject
  • schema generate field
  • schema generate platformevent
  • schema generate tab
  • static-resource generate
  • visualforce generate component
  • visualforce generate page

Many of the commands have these two helpful optional flags:

Flag Description
-d, --output-dir The directory for saving the created files. If you don’t indicate a directory, your source is added to the current folder. To add the source to an existing directory, indicate the absolute or relative path. If you don’t indicate an absolute or a relative path and the directory doesn’t exist, Salesforce CLI attempts to create it for you.
-t, --template Template used for the file creation.

If you want to know more information about a command, run it with the --help flag. For example, sf apex generate class --help.

Tip

Edit Source Files

Use your favorite code editor to edit Apex classes, Visualforce pages and components, Lightning web components, and Aura components in your project. You can also make edits in the Setup UI of your org and then use project retrieve start to retrieve those changes to your project. For Lightning pages (FlexiPage files) that are already in your org, use the shortcut to open Lightning App Builder in a scratch org from your default browser. Lightning Pages are stored in the flexipages directory.

To edit a FlexiPage in your default browser—for example, to edit the Property_Record_Page source—execute this command from the flexipages directory.

1sf org open --source-file Property_Record_Page.flexipage-meta.xml

If you want to generate a URL that loads the .flexipage-meta.xml file in Lightning App Builder but doesn’t launch your browser, use the --url-only | -r flag.

1sf org open --source-file Property_Record_Page.flexipage-meta.xml --url-only