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.


Wednesday, October 10, 2018

VSCode with Salesforce - How to install.

Visual Studio Code is a popular editor available for Windows, Mac OS and Linux. Do not confuse it with Microsoft Visual Studio. Microsoft Visual Studio is used by programmers for programming mainly on and for Windows Platform. On the other hand, Visual Studio code is a light editor used for programming languages like Java, C, C++, C#, Javascript, etc. It has basic features which are generally found in normal editors/IDEs but in addition to that it has several cool and advance features like VS Code Live Share, Slack Chat etc. It has a very rich ecosystem. Most of the features are available as extensions. 

Salesforce development support in vscode is enabled through the Salesforce extensions for VSCode (https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode).
The extension pack or bundle enables the development of visualforce, lightning component, apex and debugging in vscode. In addition to that you get code completion for apex, visualforce &lightning code. The extensions are fully developed (with support from other developers) and supported by Salesforce. Some of the blogs are referring the installation of "ForceCode" extension which is a totally different extension and unrelated to what Salesforce has released.

Visual Studio Code has in in built support for version control tools like git, but you need to install git separately.

Now let us see how to install and use Visual Studio Code.

Start by first installing latest version of Salesforce CLI. You can check the blog post https://www.salesforce-vscode.com/2018/10/salesforce-cli-installation.html for instructions.

Now download and install latest version of Visual studio code from https://code.visualstudio.com .For Windows you will see two different types of installers User Installer and System Installer. Installing the user setup does not require Administrator privileges which is very helpful in corporate environments as most of the users do not have administrator privileges. User setup also provides a smoother background update experience.



Installation is straight forward. Click on the downloaded exe and select default options in the wizard to complete the installation.

Open Visual Studio Code and click on extensions tab. Install "Salesforce Extensions for Visual Studio Code". This will install Salesforce CLI Integration for Visual Studio Code, Apex Code Editor for Visual Studio Code,Apex Debugger for Visual Studio Code,Apex Replay Debugger for Visual Studio Code,Lightning Component Code Editor for Visual Studio Code & Visualforce Code Editor for Visual Studio Code. If these are not installed automatically due to some reason , search and install these separately. 




Alternatively you can download the extensions from the VS Code extension marketplace https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode.

Code Auto Completion based on Language services requires Java 8 to be installed on the machine. Install it from here - https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. Higher versions of Java is not supported at this moment, so make sure you install the correct version, otherwise you may face issues.
Once Java is installed set the JAVA_HOME or JDK_HOME environment variable on your computer.
Alternatively you can set the path in Visual Studio Code itself. Goto File ->  Preferences -> Settings on Windows  and search for apex in the search box. Click on edit in settings.json for "Salesforcedx-vscode-apex › Java: Home". Set the java path based on you java installation.


Do a quick check of the installation by checking the command pallete. Check if SFDX commands are available in it.


We are now ready to use Visual Studio Code for development. It can be used for development against the scratch orgs or against the developer orgs, sandbox etc.
x

Monday, October 08, 2018

Getting Started with Salesforce Development with VSCode - Introduction

In this series of blog posts, we will be discussing how to use VSCode (Visual Studio Code) for development on Salesforce Platform.

Historically developers have been using different tools for development on Salesforce Platform. These tools include different IDEs (Integrated Development Environments) , Code Editors, Text Editors, Deployment tools, Data loaders etc.

The most easiest to use is the "Developer Console" provided in the Salesforce Org. Developer console is an integrated development environment with a collection of tools you can use to create, debug, and test applications in your Salesforce organization.

You can directly write code in the Org by creating classes, visualforce pages, etc. The editor provided is very basic and not very user friendly.

The Force.com IDE is a plug-in for the Eclipse IDE. This is one of most popular tools used by developers. It has source code editors, test execution tools, Querying tools etc. It can be used to create apex classes, Visualforce Pages, Lightning Components, etc.


There are some web based tools which are also quite popular like aside.io which is very fast and hence loved by developers.

These tools have several good features but shortcomings as well. Most of these are free tools provided by Salesforce or other third parties. Some are paid like Welkin Suite.

Before moving to VSCode, Salesforce tried to adopt force.com plugin for eclipse for Salesforce DX development through the Force.com IDE 2. This IDE remained in Beta and never came out of it. It was deprecated before any one could use it in day to day life. Several of the features supported by this Beta IDE are supported in VSCode. Salesforce probably dumped the IDE 2 in favour of VSCode probably because of its growing popularity. In addition to that it is quite light weight, fast and has several great features.  A good comparison between VSCode and Eclipse can be found here http://vschart.com/compare/visual-studio-code/vs/eclipse-ide


The move toward VSCode (Visual Studio Code) by Salesforce started with the development and release of Salesforce DX.  Salesforce DX was made Generally Available in Winter 18 around Oct 2017. Here is the announcement from Wade Wegner who was the product manager for Salesforce DX then  - https://developer.salesforce.com/blogs/2017/10/salesforce-dx-is-now-generally-available.html.
Before becoming generally available, Salesforce DX was a pilot and then later a Beta program. Several developers tried it and provided feedback on its various features. Some of the feedback we still see in the different releases of Salesforce DX.

Development support in VSCode for salesforce is enabled through the Salesforce extensions for VSCode. These extensions are being developed and being provided by the Salesforce Team.

In addition to that, Visual Studio Code was being used by developers way back before Salesforce officially released the Visual Studio Code extensions. This was through the ForceCode extension by John Nelson from a company named Code Science (https://www.codescience.com/blog/2016/the-new-hotness-for-salesforce-developers). There is quite a lot recent activity in this extension (https://marketplace.visualstudio.com/items?itemName=JohnAaronNelson.ForceCode). This extension was deprecated by the developer not too long ago as seen from the history of Readme file. But now it looks like the developers are working aggressively on this extension again.We now have a good competition to the Salesforce Extensions for Visual Studio Code by Salesforce.

In order to fully utilise the power of Visual Studio Code for development on Salesforce Platform, you must understand how to use the Salesforce CLI 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...