Developing a managed package in Salesforce while using Bitbucket and Git for version control and collaboration involves several steps.
This approach helps you manage your Salesforce code, configurations, and metadata in a version-controlled environment.
Here are detailed steps to develop a managed package in Salesforce using Bitbucket and Git:
Step 1: Set Up Your Salesforce Development Environment
- Salesforce Developer Edition Org:
If you don't already have one, sign up for a Salesforce Developer Edition org, which you will use for development and testing. - Install Salesforce CLI:
Install the Salesforce Command Line Interface (CLI) on your local machine. The CLI allows you to interact with Salesforce from the command line. - Install Salesforce Extensions for Visual Studio Code:Using Visual Studio Code for development is recommended, install the Salesforce Extensions for Visual Studio Code.
Step 2: Create a New Salesforce Project
In your Salesforce Developer Edition org, create a new Salesforce DX project. This project will serve as the foundation for your package development.bash# Navigate to your desired project directory
cd /path/to/your/project
# Create a new Salesforce DX project
sfdx force:project:create -n MyPackageProject
Step 3: Connect Your Salesforce Org
Step 4: Develop Your Salesforce Package ComponentsAuthenticate your Salesforce DX project with your Developer Edition org by running the following command:bashsfdx force:auth:web:login -a MyDevOrg
Develop the custom objects, fields, Apex classes, Visualforce pages, Lightning components, and other components that make up your Salesforce package.
Step 5: Initialise a Git Repository
If you haven't already, initialise a Git repository in your project directory:bash#Initialize a Git repositorygit init
Step 6: Create a Bitbucket Repository
- Log in to your Bitbucket account.
- Click the '+' icon in the left sidebar and select 'Create repository.'
- Fill in the repository details, including name, description, and access level (public or private).
- Click 'Create repository' to create your Bitbucket repository.2.
Step 7: Add and Commit Your Salesforce Project to Git
Add your Salesforce DX project's files to the Git repository and commit them:
bash#Add all files to the Git repositorygit add .
#Commit the changesgit commit -m "Initial commit"
Step 8: Connect Your Git Repository to Bitbucket
Connect your local Git repository to the Bitbucket repository you created:
bash#Replace <your_bitbucket_repository_url> with the actual URL of your Bitbucket repositorygit remote add origin <your_bitbucket_repository_url>
Step 9: Push Your Code to Bitbucket
Push your code from your local Git repository to your Bitbucket repository:
bash#Push the code to Bitbucketgit push -u origin master
Step 10: Create Package Metadata
Use Salesforce DX commands to create a package that includes the metadata for your managed package:
bash#Create a new package (replace MyPackage with your desired package name)sfdx force:package:create -n MyPackage -d "My Package Description"
#Add package components (objects, classes, etc.) to the packagesfdx force:package:version:create -p MyPackage -x -w 30
Step 11: Develop and Test Package Features
Continue developing and testing your package features within your Salesforce DX project.
Step 12: Distribute Your Managed Package
- Complete the development of your managed package.
- Go through the necessary steps to package it, including metadata and security reviews.
- Distribute your managed package through Salesforce AppExchange or other appropriate channels.