Showing posts with label Scratch Orgs. Show all posts
Showing posts with label Scratch Orgs. Show all posts

Saturday, October 20, 2018

Creating Scratch Org from a developer edition Org - Using Developer org as Dev hub

This blog post is in continuation to the previous post - Salesforce DX - Using Salesforce Developer Org as Developer Hub Org (https://www.salesforce-vscode.com/2018/10/salesforce-dx-using-salesforce.html). In the previous post we had created a developer org and enabled dev hub in the org. Now in this post we will create scratch orgs which will be associated to the dev hub org we created earlier.

First let us run sfdx force:org:list and  sfdx force:config:list to check the orgs  we have created and associated with DX installation & the configurations associated with Salesforce DX in the machine respectively. You can see that we currently only see the entry for Dev Hub org we created in the last post.


Now we will run the scratch org creation command and associate the newly created scratch org with the developer hub.

sfdx force:org:create -a MyDevOrg -s -v mydeveloperhuborg -d 30 edition=Developer

Here -s sets the created org as the default username, -a sets an alias for for the created scratch org, -v denotes alias for the target Dev Hub org, -d sets the duration of the scratch org, in days. The valid values for this parameter are from 1-30.
If the org is created, you will see a success message on the command prompt.



We will now login into the developer org and check the Developer Hub lightning application we created in previous post. In the "All Active Scratch Orgs" tab, we see an entry for the newly created org. Clicking on the Number column link, shows detail of the new org like the org id, expiration date, created date, etc.




Open the scratch org just created by running the sfdx force:org:open command, by providing the org alias.




Friday, October 19, 2018

Salesforce DX - Using Salesforce Developer Org as Developer Hub Org

Salesforce DX is source driven development.The core philosophy of Salesforce DX is that the version control is source of truth. To implement this philosophy, Salesforce has provided short lived orgs called as Scratch Orgs. These orgs can be created very easily and within a short span of time. These Scratch Orgs are connected to a central Org called as "Developer Hub" Org.

During the initial phase of release of Salesforce DX, Salesforce provided facility to enable developer Hub in Production Orgs as well as it provided Developer Hub as a 30 day trial org which can be used by people to try Salesforce DX (https://developer.salesforce.com/promotions/orgs/dx-signup). The disadvantage of this org is that after the trial period, you lose this org as well as all the scratch org associated with it. Developer Edition orgs don't expire as long as they remain active. In a Developer Edition Dev Hub, you can create up to 6 scratch orgs with a maximum of 3 active scratch orgs.

Based on customer feedback and for wider adoption, with the Winter 19 release, Salesforce is now allowing us to enable developer Hub in the developer Org itself.

In this article we will see how to enable the developer Hub in the Winter 19 developer Org.

Start by registering for a winter 19 developer Org. Open https://developer.salesforce.com/signup and register for a developer Org by filling the form.


Once you have the org created, you can login into it and use it for development purpose.


Now to enable the dev hub in the org, click on the gear icon on the top right corner to open the setup menu. Search for Dev Hub in the setup menu. You will see a toggle button with the text as "Enable Dev Hub". Toggle it to enable dev hub in this org.


Once enabled, you cannot disable the setting. Also once this setting is enabled, you will see option to enable packing in the org. We will learn about packing in future blog posts.



Now, we will connect to the developer hub org using the sfdx cli tool. We assume that you have installed the SFDX CLI tool, if not, you can follow this blog post  - https://www.salesforce-vscode.com/2018/10/salesforce-cli-installation.html.

Open command prompt and enter below command
sfdx force:auth:web:login --setdefaultdevhubusername --setalias mydeveloperhuborg

Using this command we are basically opening the developer Hub org, so that it can be used in future for creating scratch orgs. Here the alias name is set to mydeveloperhuborg.
Once you run this command you will be prompted for providing the permission so that the SFDX CLI tool can connect to the org. Once the authorisation is complete, you will see success message in the command prompt.


Let us now create a simple lightning app so that we can group the Salesforce DX, Scratch Org related tabs.



Create a new lightning app. Lets give it a name of "Developer Hub". Include DX related tabs like "Active Scratch Orgs, "Scratch Org Infos" and "Namespace Registries".



You will now be able to see the scratch org information grouped in this app. Currently there are none in the screen shot as we have not created any. We will see how to create scratch orgs and link it with this org in the next blog post.


 Note: You cannot enable Dev Hub in a Developer Edition org in which you have defined a namespace. You cannot define a namespace in a Developer Edition org that has Dev Hub enabled.

Salesforce CLI Installation


Salesforce CLI which was earlier called as Salesforce DX CLI is a command line tool. It is heart of Salesforce DX feature. It is extensible, you can create plugins in case you find some functionality missing. See here (https://developer.salesforce.com/blogs/2018/05/create-your-first-salesforce-cli-plugin.html). Salesforce keeps enhancing the tool by adding new functionalities in its releases. It is very powerful and can be used to do following operations.
  • Creating Scratch orgs
  • Connecting to Developer Hub orgs, Scratch Orgs, Sandboxes, Developer Orgs, etc
  • Creating code like apex classes, Visualforce pages, lightning component etc.
  • Getting the source code from scratch orgs, sandboxes, and developer orgs into local machine and pushing updated code to these orgs.
  • Creating packages, package installations etc.


In order to get started with Salesforce DX, we must install the Salesforce CLI. The tool can be downloded from https://developer.salesforce.com/tools/sfdxcli. It is available for Windows, Mac OS and Linux.

We will see the process of installation on Windows.


Click on the "Download for Windows 64" link, which will download the CLI installation file on your machine. Click on the installation file, it will start the installation process prompting you to select the components. Keep the default selected and click next.
Now select the path where you want to install the CLI. You can keep the default path, click next to continue.


The installation process will start copying the files to your file system. It will take some time for installation to finish. Once the installation is finished, you can check if the installation is completed successfully by running the sfdx --version command on the command prompt. On successful run of the command, you will see the version number printed on the command line. Run the cmd command from Windows -> Run. In future blog posts, we will see how to use the tool.


Salesforce Flow Tutorial #3 - What is Record Triggered Flow - Post To Chatter

 In this tutorial we will learn how to create and use Record Triggered Flow. The Record triggered flow can be used to fulfill requirements w...