Package Development Model
Use the Package Development model to develop against orgs with source tracking, such as scratch orgs. This model tracks the changes you make on your local workstation and in your default development org.
In the Org Development model, your Salesforce org’s monolith of unpackaged metadata contains all the metadata that belongs to a custom app or extension. Because that metadata isn’t isolated or organized, it can be difficult to understand, upgrade, and maintain as the complexity of your org grows.
In the Package Development model, you can organize your unpackaged metadata in your production org into well-defined packages in a DX project by creating multiple package directories. Your end goal is to create packages using those directories that are versionable, easy to maintain, update, install, and upgrade.
For more information, see the Package Development Model Trailhead module.
To develop with this model:
- From the Command Palette, run SFDX: Create Project.
Alternatively, to work on an existing project, choose File > Open and navigate to the project directory. Before you open an existing project in VS Code, make sure that your project has a
sfdx-project.json
file and that metadata is in source format.- For information on the project structure, see Project Setup in the Salesforce DX Developer Guide.
- You can work with source-tracked orgs only if your metadata is in source format.
- In the status bar, click Org Picker to open the Command Palette.
- If you don’t have a Dev Hub, see Enable Dev Hub in Your Org in the Salesforce DX Setup Guide.
- Run SFDX: Authorize an Org.
- Click Org Picker and run SFDX: Create a Default Scratch Org to create and set a scratch org as your default org for development. For more information, see Scratch Orgs in the Salesforce DX Developer Guide.
- Select the scratch org shape, enter an alias, and enter the duration when the scratch org expires. The Org Picker now shows the alias provided for the scratch org. Click the browser icon in the status bar to open the default org you are working against. To change the default org you’re developing against, click the Org Picker and select a different org. Or, open the Command Palette and run SFDX: Authorize an Org or SFDX: Create a Default Scratch Org.
When you use the package development model, it’s simple to keep your local project and default development org in sync. Because you deploy your changes to other orgs using packaged sets of metadata, there’s no need to manually track your changes. VS Code is context aware that you are working in a scratch org and provides only push and pull commands, not commands to retrieve and deploy source.
To push your source to the default scratch org, run SFDX: Push Source to Default Scratch Org.
If you want the changes in the project to overwrite changes in the scratch org, run SFDX: Push Source to Default Scratch Org and Override Conflicts.
After you make changes in your scratch org, run SFDX: Pull Source from Default Scratch Org to update your project.
If you want the changes in the scratch org to overwrite changes in the project, run SFDX: Pull Source from Default Scratch Org and Override Conflicts.
Before you push local changes to the scratch org or pull remote changes to the local project, you can see the changes in the Output panel. To do so, run SFDX: View Changes in Default Scratch Org from the Command Palette.
- Source Format
- Salesforce Developers Blog: Choose the Right Salesforce Org for the Right Job