In this fourth part of the salesforce DX series, I am going to show how to set up the Salesforce DX from the existing source base by creating the temporary package. If you are already a Salesforce developer or ISV, you likely have the existing source in a managed package in your packaging org or some application source in your sandbox or production org. Before you begin using Salesforce DX, retrieve the existing source and convert it to the Salesforce DX project format.When you convert existing Metadata API source to Salesforce DX project format, we create an XML file for each bit. All files that contain XML markup now have an .xml extension. You can then look at your source files using an XML editor. To sync your local projects and scratch orgs, Salesforce DX projects use a particular directory structure for custom objects, custom object translations, Lightning components, and documents.
1. Retrieve the Metadata
Create an unmanaged package in your existing org, and include all the component you want to move to your Salesforce DX project. You can do it by login into the salesforce dev or sandbox.
2. Login into Dev Hub from CLI
Run the force:auth:web:login CLI command. If you are authorizing a Dev Hub org, use the –setdefaultdevhubusername parameter if you want the Dev Hub org to be the default for commands that accept the –targetdevhubusername parameter.
A Salesforce DX project has a specific structure and a configuration file that identifies the directory as a Salesforce DX project.Use the force:project:create command to create a skeleton project structure for your Salesforce DX project.
sfdx force:project:create --projectname DXMigration
4. Login into Salesforce Source Org
Now you need to login into the salesforce source org from where you wanted to fetch metadata into the salesforce scratch org. Use below command to connect to the developer account or sandbox.
sfdx force:auth:web:login -a my-dev-org
5. Export The Package
Export the unmanaged package metadata in a temporary directory. Type the following commands in the root folder of your Salesforce DX project:
Unzip the unpackaged.zip file and optionally delete the unpackaged.zip file
6. Convert Source code to Salesforce DX
Convert the source code to the Salesforce DX project structure by running the following commands.
sfdx force:mdapi:convert -r ./temp
7. Create a Scratch Org for Development
You can create scratch orgs for different functions, such as for feature development, for development of packages that contain a namespace, or for user acceptance testing.Run the following commands to create a scratch org .