Salesforce DX Absolute Beginner ( Part 5 Of 7 )

In this fifth part of the salesforce DX series, I am going to show how to set up the Salesforce DX from the existing source base without creating the package.In this post, I am extracting the metadata from the salesforce into the eclipse project. We will use this project metadata to convert into the salesforce DX specific format.

1. Retrieve the Metadata

Create an eclipse project to extract the metadata from the salesforce.

 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.

sfdx force:auth:web:login --setdefaultdevhubusername --setalias my-sfdchub-org-pkg

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.

sfdx force:project:create --projectname DXEx
cd DXEx

4. Export The Package.xml

Export the package.xml file into the temporary directory. Type the following commands in the root folder of your Salesforce DX project:

sfdx force:mdapi:retrieve -r ./mdapipkg -u my-dev-org1 -k  C:\Users\rvakati\workspace\RajV\src\package.xml

Unzip the file  which is created from the above command  and optionally delete the file

 5. 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 --rootdir mdapipkg --outputdir force-app
6. Create a Scratch Org for Development

 You can create scratch org by Run the following commands.

sfdx force:org:create -f config/project-scratch-def.json --setdefaultusername --setalias my-dx-scratchorg-pck
7.Push Metadata into the scratch org
You can push the extracted metadata into the scratch org by running the below command into the scratch org.
sfdx force:source:push

8.Open scratch org

You can open scratch org by running following command.

	sfdx force:org:open

9. 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.

sfdx force:apex:class:create  --classname DemoClass --template DefaultApexClass --outputdir force-app/main/default/classes/
10.Push Metadata into the scratch org
You can push the changes into the scratch org by running the below command.
sfdx force:source:push

Quick Recap of part 5 before going to part 6

  • Create an Eclipse Project to extract metadata from the salesforce
  • Convert package.xml file into Salesforce DX format.