Salesforce DX Absolute Beginner ( Part 7 Of 7 )

In this seventh part of the salesforce DX series, I am going to show how to use salesforce DX data commands to migrate the sample data from the scratch org to sandbox for testing or you can create data into the scratch org from the CLI.
Use force:data:soql:query command to Executes a SOQL query as shoe below.This Command will help if you wanted to retrieve data into CLI from scratch org without login. Use -t for tooling API 



 

Export Command 
 Exports data from an org into the sObject tree format  as shown below

 

Import Command 
 Imports data into an org using the SObject Tree Save API. This data can include master-detail relationships. The following command imports the data into Salesforce objects by using SObject Tree.

Create/Update/Delete Commands 
 You can use CRUD commands to manipulate the data the CLI as shown below.
Below example showing the how to inserts account record from the CLI.
Below example showing the how to delete account record from the CLI.
Below example showing the how to update account record from the CLI.

Bulk Commands 

 You can use Bulk commands to delete or upsert the data into Bulk API Style.

The Following commands Create a job and one or more batches for inserting new rows and updating existing rows by accessing the Bulk API.

Above Command Inserts or updates records from a CSV file with one or more batch based on the CSV, file size and Returns a job ID and a batch ID. Use these IDs to check job status with data:bulk: status as shown below.

 

Below are some of the useful reference about salesforce DX

  1.  Salesforce DX Trailhead
  2. First Impressions with Salesforce DX by Peter Chittum
  3. Getting Started With Salesforce DX

Salesforce DX Absolute Beginner ( Part 6 Of 7 )

In this sixth part of the salesforce DX series, In this post, I am going to explain how to migrate changes from the scratch org to salesforce sandbox for testing.  When you’re ready to validate your source, convert your Salesforce DX source to Metadata API source format. You can then deploy to a sandbox.You can deploy or retrieve up to 10,000 files at once. The maximum size of the deployed or retrieved .zip file is 400 MB (39 MB compressed). If either limit is exceeded, the operation fails.You can increase the efficiency of your sandbox and production deployments by using tests you’ve already done in the scratch org. Run only the tests that are required, such as tests for Apex classes and triggers that change for the deployment. To run only specified tests when you deploy, set -l to RunSpecifiedTests and use -r to specify a comma-separated list of tests for deployment-specific changes to your Apex code.
  1.Pull Changes from Scratch Org 

To ensure that your project is up to date, synchronize the source in your local file system with your development scratch org by running the pull command.


2.Login to the sandbox

Login into the sandbox by running the following command. Set alias name so that you can refer it easily for further.

3.Convert Salesforce DX project into metadata project

create the directory for your source and convert the source to Metadata API format as shown below

4.Deploy Metadata into Sandbox 

Deploy the metadata from the directory to the sandbox, specifying deployment-specific tests as needed by running this command.

If your deployment exceeds the wait time before it completes, use force:mdapi:deploy:report to check the deployment status. The default wait time is 0 minutes. Use the –wait parameter to specify a longer wait time.

For example, to check a deployment job and add 5 more minutes to the wait time

Quick Recap of part 6 before going to part 7

  • Pull Changes from scratch org
  • Login to sandbox
  • Convert DX project to salesforce metadata.
  • Deploy changes to the sandbox.

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.

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

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

 5. Convert Source code to Salesforce  DX 

Convert the source code to the Salesforce DX project structure by running the following commands

6. Create a Scratch Org for Development

 You can create scratch org by Run the following commands.

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.

8.Open scratch org

You can open scratch org by running following command.

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.

10.Push Metadata into the scratch org
You can push the changes into the scratch org by running the below command.

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.

 

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

Salesforce DX Absolute Beginner ( Part 3 Of 7 )

In this third part of the salesforce DX series, I am going to show how to set up salesforce dx project from the beginning. I am assuming that you are implementing the new application or project from the beginning. So there is no salesforce metadata is configured. Follow this basic workflow when you are starting the application from the beginning

1. Login into Dev Hub from CLI 

First, you need to login to the Dev Hub from the CLI to start the new project.
 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.

After Successful login into the Dev Hub, you can see the success message into the CLI as shown below.

 2. Create an SFDX 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. The force:project:create command generates these samples configuration files to get you started.

 The force:project:create command generates these samples as shown below.
 3. 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 and much other use cases. Use force:org: create to create a scratch orgs .

4.Open scratch Org
 You can open scratch org by running force:org:open command from the CLI. After login into the scratch org, you can make any configuration changes. Later you can pull them into local folders.

Or

5. Push and Pull the code

Go and create some couple of objects in the salesforce scratch org after that we will pull into the local salesforce dx by using the pull commands. You can pull configuration and code from scratch org by using force:source:pull command.

Create an Apex Class from the CLI with below command

Make some changes to the code as shown below.
Now push the changes to Scratch org from the local development with force:source:push command
After successfully push, you can able to see the changes in the scratch org
Here are the overall highlights of this post before starting part 4.
  •  Login to the Dev Hub
  • Create a Scratch Org
  • Create Salesforce DX Project
  • Pull changes into Salesforce DX project from the scratch org
  • Make changes locally and push into scratch org.