Create a Custom Object
You can use Salesforce CLI to generate the metadata files for new custom objects in your local Salesforce DX project.
- Open a terminal (macOS and Linux) or command prompt Windows and change to your Salesforce DX project directory.
-
Run the interactive schema generate
sobject command. You must specify a label for your new custom
object 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.
sf schema generate sobject --label "New Object"
Answer all the questions about your new object, such as the location of the generated files in your Salesforce DX project and whether to enable various object properties.
After you create your custom object:
- Create a custom field on your new object with the interactive schema generate field command, which generates the necessary metadata files in your project. You can also use the command to create a custom field on a standard object, such as Account.
- Create a custom tab for your new object with the schema generate tab command.
Then deploy your new custom object to your org.
sf project deploy start --metadata CustomObject:NewObject__c --target-org myscratch
The first time you deploy your new custom object to a source-tracking org, the org creates additional properties and sets new defaults on it. For this reason, we recommend that you immediately retrieve the custom object so your local source files are updated with this new information.