Facts on Salesforce DX Project

What is Salesforce DX Project?

Salesforce DX introduces a new project structure for your org’s metadata (code and configuration), your org templates, your sample data, and all your team’s tests. Store these items in a version control system (VCS) to bring consistency to your team’s development processes. Retrieve the contents of your team’s repository when you’re ready to develop a new feature.

A Salesforce DX project has a specific structure and a configuration file that identifies the directory as a Salesforce DX project.

Note:-  In practice, you would name the project something that is more descriptive of its purpose, like sfdx-sales-app or sfdx-expense-tracker-app.

What are the different options to create a Salesforce DX project?

Use the Sample Repository on GitHub Explore the features of Salesforce DX using one of the sample repos and your own VCS and toolset.
Create a Salesforce DX Project from Existing Source Start with an existing Salesforce app to create a Salesforce DX project.
Create a Salesforce DX Project Create an app on the Lightning Platform using a Salesforce DX project.

Sample Repository on GitHub

If you want to check out Salesforce DX features quickly, start with the sfdx-simple GitHub repo. It contains an example of the project configuration file (sfdx-project.json), a simple Salesforce app, and Apex tests.

Cloning this repo creates the directory sfdx-simple. Assuming that you’ve already set up Git, use the git clone command to clone the master branch of the repo from the command line.

To use SSH:- git clone git@github.com:forcedotcom/sfdx-simple.git

To use HTTPS: git clone https://github.com/forcedotcom/sfdx-simple.git

Note:- In the above command, forcedotcom is the username of GitHub account and sfdx-simple.git is the repository name.

Another simple way to do it is to download a .zip file of the repository’s source using Clone or download on the GitHub website. Unpack the source anywhere on your local file system.

Assuming that you’ve already set up Git, Visual Studio Code and Salesforce CLI, another way of doing it is:-

  • Open your visual studio code and Press ctrl+shift+p. It will open the command palette.

Untitled1.png

  • type Git: Clone
  • It will ask the Repository URL, Once you provide the Repository URL, press enter.

Capture3.PNG

  • A window will pop up to select the path directory. Select a folder and enter
  •  The command will get execute and once it is finished, it will give you an option saying:-

Capture

Once You select Open Repository, You editor will look like this:-

Capture1.PNG

Create a Salesforce DX Project from Existing Source

If you are already a Salesforce developer or ISV, you likely have an 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 source format.

  1. Create a Salesforce DX project.
  2. Create a directory for the metadata retrieve. You can create this directory anywhere. Use mkdir mdapipkg.
  3. Retrieve your metadata source.
    The format of Current Source How to Retrieve Your Source for Conversion
    You are a partner who has your source already defined as a managed package in your packaging org. Retrieve Source from an Existing Managed Package
    You have a package.xml file that defines your unpackaged source. Retrieve Unpackaged Source Defined in a package.xml File

     

Retrieve Source from an Existing Managed Package

  1. In the project, create a folder to store what’s retrieved from your org, for example, Use mkdir mdapipkg.
  2. Retrieve the metadata.

sfdx force:mdapi:retrieve -s -r ./mdapipkg -u <username> -p <package name>

The username can be a username or alias for the target org (such as a packaging org) from which you’re pulling metadata. The -s parameter indicates that you’re retrieving a single package. If your package name contains a space, enclose the name in single quotes.

-p ‘Test Package’

After you retrieve the source from your org, you can complete the configuration of your project and convert the metadata source to source format.

The convert command ignores all files that start with a “dot,” such as .DS_Store. To exclude more files from the convert process, add a .forceignore file.

  1. To indicate which package directory is the default, update the sfdx-project.json file.
  2. Convert metadata format to source format.

sfdx force:mdapi:convert –rootdir <retrieve dir name>

The –rootdir parameter is the name of the directory that contains the metadata source, that is, one of the package directories or subdirectories defined in the sfdx-project.json file.

If you don’t indicate an output directory with the –outputdir parameter, the converted source is stored in the default package directory indicated in the sfdx-project.json file. If the output directory is located outside of the project, you can indicate its location using an absolute path.

Retrieve Unpackaged Source Defined in a package.xml File

If you already have a package.xml file, you can retrieve it, unzip it in your local project, and convert it to source format. You can do all these tasks from the CLI. The package.xml file defines the source you want to retrieve.

But what if you don’t have a package.xml file already created? See Sample package.xml Manifest Files in the Metadata API Developer Guide.

  1. In the project, create a folder to store what’s retrieved from your org, for example, mdapipkg.
  2. Retrieve the metadata.
    sfdx force:mdapi:retrieve -r ./mdapipkg -u <username> -k ./package.xml
    The username can be the scratch org username or an alias. The -k parameter indicates the path to the package.xml file, which is the unpackaged manifest of components to retrieve.

Refer below image to create a project with Manifest which consists package.xml file:-

Untitled.png

Untitled1

Capture

Capture1

Authorize an org:-

Untitled

select the URL to login:-

Untitled1

Give an alias to your org to use it later:-

Untitled2.png

CaptureCapture1

After authorization, open terminal in the VS Code and write below command:-

sfdx force:source:retrieve –manifest C:\Users\HP\Desktop\retrieveMetadataFromPackage\manifest\package.xml

Note:- Change the path directory accordingly. The path would be where your package.xml exist.

Refresh the folder and You will see the metadata in default/main folder.

111

Create a Salesforce DX Project

A Salesforce DX project has a specific structure and a configuration file that identifies the directory as a Salesforce DX project.
  1. Use the force:project:create command to create a skeleton project structure for your Salesforce DX project. If you don’t indicate an output directory, the project directory is created in the current location. You can also specify the default package directory to target when syncing source to and from the scratch org. If you don’t indicate a default package directory, this command creates a default package directory, force-app.
    The force:project:create command generates these samples configuration files to get you started:

    • sfdx-project.json
    • config/project-scratch-def.json
    • .forceignore

     

Example

sfdx force:project:create --projectname mywork

sfdx force:project:create --projectname mywork --defaultpackagedir myapp

Another way to create a project is by using the Visual Studio Code. Steps to follow:-
  • Press Ctrl+shift+p and select sfdx: create project

Untitled

  • Give a project name and press enter. A popup will appear to select the destination of the project. Once selected, your project is ready.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s