Deployment
Apex Deployment
Deploying Apex Code
Apex deployment uses Change Sets or Salesforce CLI.
Introduction to Apex Deployment
Apex deployment is a crucial step in moving your Salesforce development work from a sandbox environment to a production environment. Salesforce provides two primary methods for deploying Apex code: Change Sets and the Salesforce CLI. Each method has its benefits and use cases.
Deploying Apex with Change Sets
Change Sets are a point-and-click tool in Salesforce that allows you to package up and deploy your Apex code and other metadata from one Salesforce org to another. This method is ideal for users who prefer a more visual interface or who are not comfortable with command-line tools.
Creating a Change Set
To create a Change Set, follow these steps:
- Log in to your Salesforce Sandbox org.
- Navigate to Setup.
- Enter Change Sets in the Quick Find box, then select Outbound Change Sets.
- Click New to create a new Change Set.
- Give your Change Set a name and description, then click Save.
Uploading and Deploying a Change Set
Once your Change Set is complete, you need to upload it to the target org. Here's how:
- In your Change Set, click Add to include components like Apex classes or triggers.
- After adding components, click Upload and select the target org (e.g., Production).
- Log in to the target org and navigate to Inbound Change Sets to deploy.
- Locate your Change Set, validate it (if necessary), and then click Deploy.
Deploying Apex with Salesforce CLI
For developers who prefer using command-line tools, the Salesforce CLI offers a powerful alternative for deploying Apex code. This method is more suitable for complex deployments, automation scripts, or when integrating with CI/CD pipelines.
Setting Up Salesforce CLI
Before deploying Apex via Salesforce CLI, ensure you have the CLI installed and authenticated to your Salesforce org. Follow these steps:
- Download and install the Salesforce CLI from the official website.
- Open your terminal or command prompt.
- Authenticate your org using the command:
sfdx auth:web:login -a MyOrgAlias
. This command opens a browser window for you to log in to Salesforce.
Deploying Apex Code Using CLI
Once authenticated, deploy your code using the following steps:
- Navigate to the directory containing your Apex code.
- Run the command:
sfdx force:source:deploy -p path/to/your/apex/code
. - Monitor the deployment process directly in your terminal window.
- Use additional flags such as
--checkonly
to validate the deployment without actually deploying.
Conclusion
Both Change Sets and the Salesforce CLI offer robust solutions for deploying Apex code. Change Sets are user-friendly and ideal for simpler deployments, while the CLI is better suited for developers who require more control and automation. Choose the method that best fits your workflow and project requirements.
Deployment
- Deployment
- Metadata API
- Tooling API
- Previous
- Test Data
- Next
- Metadata API