Salesforce DX Absolute Beginner ( Part 4 Of 7 )

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.

3. Create a DX Project

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.

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.

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.


 

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 .

 8.Push Metadata into the scratch org
You can push the extracted metadata into the scratch org by running the below command.

9: Open scratch org

You can open scratch org by running following command.

10. Pull Changes from Scratch Org, if any needed 

11. Implement the new features

Now if you wanted to make any changes you can do in the scratch org . In this example, you can create an apex class by running this command.

push changes to scratch org again after development by running the following command.

Quick Recap of part 4  going to part 5
  • Salesforce DX  Project setup
  • Converting metadata into DX specific format
  • Making changes and push to scratch org