SFDC Stop - Always the latest about Salesforce


Full Tutorial Series with videos, free apps, live sessions, salesforce consulting and much more.


Telegram logo   Join our Telegram Channel

Tuesday, 21 July 2020

Salesforce LWC Tutorial Part 1 | ToDo App Project | Designing the markup in SLDS

Hello Trailblazers,

Welcome to the first tutorial in LWC Tutorial Series. We're focusing on the concept of Learning By Doing in this tutorial series and following that, it's time to get started with our first project in LWC which is a ToDo Application. In this tutorial, we'll be designing the markup in SLDS for our ToDo application and going forward in further tutorials, we'll be adding JavaScript in our application to make it working as shown below:-


So, let's start building the above application and while doing that, we're going to see from very basic, how we can built the HTML structure by looking at a design and we'll learn about various lightning tags and what's their usage on the go.

This tutorial is published on SFDC Stop YouTube Channel. So, if you want to learn in detail, have a look at the tutorial video down below. Otherwise, you can scroll down to have a look at the code gist with explanation where we created the markup of our ToDo Application

Tutorial Video


Code Gist with Explanation

I highly recommend you to have a look at the video to understand the thinking process like:- How I proceeded with creation of this component by just having a look at the design. However, I'll be explaining the code of the same below. So, let's have a look at the code using which we created our first ToDo App LWC component. My component name is todo and the code is given below:-

HTML Snippet (todo.html)

As you can see in the above code, I have first of all created a lightning-card with a title ToDo List. I added a lightning-button-icon in the actions slot of the card with the icon of sync. I used slds icons to find out which icon I should use for this purpose. Next, I created the card body using lightning-layout and also created a paragraph which I added to the footer slot of the card.

Let's learn in detail about the card body first, inside the lightning-layout, I added a lightning-layout-item with padding as around-small in order to give equal padding from the border to all the list items and I specified the size to 12 as each row in lightning-layout can be divided into 12 columns at max, so, I wanted the card body to take/cover the maximum width available.

After that, I created an unordered list by referring to the slds code shown here and under each list item, I again created a lightning-layout as I wanted to divide the list item into two parts, one for the task name and other for the delete button which will be used to delete the task. This lightning-layout has a vertical-align property of center so that the text (task name) is aligned middle in vertical direction to look good with delete button and also, I specified a horizontal-align property to spread as I want the items in the task row i.e. the task name and delete button to spread evenly in the width available.

As specified above, each lightning-layout under the list item has two lightning-layout-item one for task name and one for delete button. I have given the padding as horizontal-small to both these lightning-layout-item so that they're properly spaced from each other and also from the corners. I again used lightning-button-icon in order to create delete button for each task.

Moving onto the footer code, I again used lightning-layout but this time I specified a property named as pull-to-boundary as small in order to make sure that the text field and the button that I am going to create should stick with their boundaries irrespective of the width. I created two lightning-layout-item inside that. Again, these two are having a padding of horizontal-small so that they're placed away from each other and from the footer corners as well.

In the first lightning-layout-item, I added the property of flexibility as grow because I want the input field to grow as the width increases, I didn't add this property to the second lightning-layout-item where I am going to place the button because I want the button to have a fixed width as it shouldn't grow depending on the container width.

Finally, I added a lightning-input field to the first layout item with a placeholder as Enter new task so that it's shown as a hint and I also specified the variant as label-hidden as I didn't want a label for this field. I also made this field required as it's important to add a task name before adding it to the todo list. For the second layout item, I just added a simple lightning-button with variant as brand as I wanted it to be blue in color. I specified the label of this button as Add, as this button will be used to add elements to the todo list.

The output of the above code i.e. the final design is shown below:-



That's all for this tutorial. I hope you liked it. All the code used in this tutorial is available on GitHub and you can have a look at that by clicking here. Make sure to have a look at the video if you want to learn in detail and let me know your feedback in the comments down below.

Happy Trailblazing..!!

Saturday, 18 July 2020

Getting Started with LWC | Setup local server for Lightning web components | First LWC Component

Hello Trailblazers,

Welcome to the first tutorial in LWC Tutorial Series. In this tutorial, we'll cover the below points :-

1. What is LWC ?
2. Why should we use LWC when Aura is here ? 😎
3. Comparison between Old and New Web Stacks
4. Setting up Local Server for Lightning web component development
5. Creating your first LWC component with a little bit of HTML and JavaScript
6. Have a look at the references and resources for learning LWC

This tutorial is published on SFDC Stop YouTube Channel. So, if you want to learn in detail, have a look at the tutorial video down below. Otherwise, you can scroll down to the presentation and have a look at the code gist with brief explanation where we created our First LWC Component

Tutorial Video


Presentation

The presentation used in this tutorial is published on Slideshare and can be viewed below.

Code Gist with brief Explanation

Now let's have a look at the code using which we created our first LWC component. My component name is myFirstLWC and the code is given below:-

HTML Snippet (myFirstLWC.html)

As you can see in the above code, I created a simple lighting-card that consist of a lightning-input field with a label Write your Name. This field has an onchange handler associated which is calling my updateName method present in the javascript file. The value of this field is binded with the name variable which we're going to define in our js file. Below that, we just have displayed a text as:- Hello {name}, Welcome to your first LWC Component. In this statement everything is static except the name variable which is declared in the JavaScript file and being used here, by specifying it within curly braces{}.

JavaScript Snippet (myFirstLWC.js)

As you can see above, I have just created a name variable which is having a default value empty. Below that we have our updateName method defined which is responsible to udpate the name variable with the value of the input field as this method will be called automatically whenever the value of input field is changed by reacting to the onchange handler. The onchange event will be passed onto this method automatically and inside this method, we're getting the reference to the HTML element which is changed by using event.target. As, we need the value of that HTML element, we're getting that using event.target.value. We're assigning that value to the name variable that will automatically cause the HTML to re-render as the name variable used in HTML as {name}, is updated now.

The component will look like this initially:-


As you click on the lightning-input field and write anything there. The component will be re-rendered automatically and you'll see your text after hello as shown below:-


I am viewing the LWC component in the LWC Local Server that I've setup in my system. If you've Node.js and SFDX CLI installed in your system, you can also setup the local LWC Server by executing the below commands in the terminal:-

sfdx plugins:install @salesforce/lwc-dev-server

The above command will install lwc-dev-server in your local system. After it's installed, open the terminal again and run the below command:-

sfdx plugins:update

This command will basically update all the sfdx plugins so that you can run your LWC component on the local server installed.

After your local server is installed successfully, you can preview the LWC component by right clicking on the lwc component in your VSCode project and choosing SFDX: Preview Component Locally option as shown below:-


Choose the first option, i.e. Use Desktop Browser to preview the component locally in your default browser as shown below:-


Make sure you have Salesforce Extension Pack installed in VSCode. You can have a look at this tutorial to setup VSCode for Salesforce Development:- How to setup Visual Studio Code for Salesforce ?

You can also use the below command to start the local dev server in case the extensions are not working properly:-

sfdx force:lightning:lwc:start

In case you're follwing some issues, installing the sfdx plugins, read the instructions carefully as it's possible that you're missing some node js packages, you can install those packages by using the below command:-

npm install -g <package name>

-g  is basically used to install the package globally so that you can use it anywhere.

That's all for this tutorial. I hope you liked it. All the code used in this tutorial is available on GitHub and you can have a look at that by clicking here. Make sure to have a look at the video if you want to learn in detail and let me know your feedback in the comments down below.

Happy Trailblazing..!!

Tuesday, 30 June 2020

Extract Update and Deploy Metadata to Salesforce Org | SFDX Deploy Tool | Deploy Extracted Metadata

Hello Trailblazers,

In this tutorial, we're going to learn how we can very easily extract, update and then deploy metadata to a Salesforce Org by executing a single command from SFDX Deploy Tool for Windows.

Use Case:- In real life projects, when we're actually working in Salesforce, it usually happens that we need to deploy some metadata from one Salesforce Environment to another, let's say you've completed a feature in developer environment and you need to push all the changes to a QA sandbox, while pushing the changes it usually happens that we face some deployment issues, and we need to update some metadata and then try to deploy again and again. This can be very hectic specifically if you're using change sets which take time to upload and then you need to wait for it to be available in the destination org where you want to deploy.

We'll learn how we can make those deployments very easy using SFDX Deploy Tool for Windows

SFDX Deploy Tool can be downloaded from the github repository here:- https://github.com/rahulmalhotra/SFDX-Deploy-Tool

For this tutorial, we need SFDX Deploy Tool to be already setup with you. If you want to know more about how to setup SFDX Deploy Tool, have a look at the README file of the GitHub repository or have a look at this blog post or the tutorial below:-


Once you've setup SFDX Deploy Tool, i.e. the source and destination orgs, where you have to pull and push the metadata respectively. You can open the tool and you'll see the below screen:-


As you can see in the above image, I have updated this tool and added 3 more options at number:- 2, 5 and 6. These options are:-
  • Extract fetched metadata at option 2
  • Validate extracted metadata in destination org at opton 5
  • Deploy extracted metadata in destination org at option 6

Once you've setup the tool, the first step you need to do is to fetch the metadata from the source org. That you can do by setting up the package.xml present under the metadata folder. After you have the package.xml ready, open the deploy tool, choose option 1 and press the Enter key. A sample package.xml is shown below:-


Once you've fetched the metadata from the source org, you'll see an unpackaged.zip file automatically created in the base folder as shown in the above image. This zip file mainly consists of all the metadata that you've fetched using the package.xml. Our next step is to extract and update this metadata before deploying it to the destination org.

To extract the metadata, open SFDX Deploy Tool and choose option 2 with the name:- Extract fetched metadata this option will extract the fetched metadata using windows powershell, once the metadata is successfully extracted, you'll see an output as shown below:-


In the base folder, you can see that the unpackaged.zip file is extracted automatically and a new folder named unpackaged is created which consist of all the metadata that we fetched from the source org as shown below:-



In case you don't have powershell in your windows you can use any other tool to extract that zip file. Now, we can simply open any metadata and update it. Once, we've updated the metadata, it's time to validate and deploy the extracted metadata.

To Validate Extracted Metadata:- Open SFDX Deploy Tool and choose option 5 with the name:- Validate extracted metadata in destination org

To Deploy Extracted Metadata:- Open SFDX Deploy Tool and choose option 6 with the name:- Deploy extracted metadata in destination org. This option will automatically pick the updated files in the extracted folder and deploy them to your destination org.

If you face errors while deployment, you can simply update the extracted files in VSCode and use SFDX Deploy Tool to deploy the metadata again and again in a single command.

Tired of reading or just scrolled down ? Don't worry, you can watch the video too:-



That's all for this tutorial everyone. I hope you liked it, give a try to SFDX Deploy Tool and let me know your feedback in the comments down below.

Happy Trailblazing..!!

Sunday, 28 June 2020

Salesforce Git Codelab | Learn By Doing | Live Deployment | SFDC Stop | GitHub Actions

Hello Trailblazers,

Good News :-) We recently crossed 2500 subscribers on YouTube...!! Thank you for being supportive all the time, you have made it possible.

To celebrate this, I am very excited to present the first CodeLab from SFDC Stop:- "Salesforce Git CodeLab" where you'll learn about the concepts of git by actually coding yourself and finally, you'll be having your name in the SFDC Stop Contributors after completing the code lab.

The Salesforce Git Codelab will be live today i.e. 28th of June 2020 at 7 P.M. IST on SFDC Stop YouTube Channel. and I'll be available on the live chat to answer any questions that you have during the premiere.

So, make sure to set a reminder for the premiere by clicking on the below video or subscribe to the channel to get notified



See you soon...!!

All the instructions regarding the codelab are also available in the README file of the GitHub Repository that you can follow in order to complete it. Have a look at the GitHub repository by clicking here.

Happy Trailblazing..!!

Sunday, 7 June 2020

How to connect VSCode Salesforce Project to GitHub ? | Getting Started with Version Control System

Hello Trailblazers,

In this post, we're going to learn how we can connect VSCode Saleforce Project to GitHub. We're going to create a new GitHub repository, commit our changes and push it to our GitHub repository. Let's Begin.

Download Git

The first step is to download and install git in your system. In order to download git, go to this link:-  https://git-scm.com/downloads and you'll see the below screen.


Git is available for Mac, Windows and Linux. Download by clicking on the button as shown in the above image and follow simple steps to install git in your system.

Initialize git in VSCode

Now, as you've installed git in your system, move on to your Salesforce Project in VSCode and click on Initialize Repository button available on the 3rd section in the left side bar as shown below:-


As you click on this button, it will automatically initialize the repository for you as shown below:-


If you want to initialize repository using command, you can just open terminal and write git init and press enter in order to initialize a new repository in the project folder. You can see in the above image, in the left sidebar, we're having all the files with an indicaton U where U means Untracked i.e. these files are currently not being tracked by git.

Commiting the files

Just to give you a brief overview:-  Git is a version control system which basically tracks all the changes that you're doing. Any new file that you create is initially Untracked. Each file in a git repository can be in one of the below state:-

1. Untracked:- When a new file is created by the user, it is untracked or we can say that this file is unknown to git.

2. Tracked / Index Added:- When we specify or tell git that this is a newly created file and you've to track this file (particularly known as staging the file), the status of the file is changed to tracked or we can say that a particular index (number) is given to the file so that it can be identified by git.

3. Committed:- When we're done with the required changes, we commit that file. Git mark that file as committed and add an entry in  it's internal changelog which has the required updates with a Commit Message.

4. Untracked / Modified:- When a previously commited file is updated, the status of the file is changed to untracked / modified. We need to stage this file again to tell git that this file is ready to be committed.

5. Tracked / Index Modified:- When a modified file is staged by the user, it's status is again changed to tracked. At this point the index of the file is modified with recent changes and the file is again ready to be committed.

The basic flow for new files will be:-

Untracked -> Index Added (Tracked) -> Committed

and for existing files that are committed before, the flow will be:-

Untracked -> Index Modified (Tracked) -> Committed

So, we've just initialized a git repository and all our files are untracked by default. The next step is to stage the files. This basically tells git that these are the files in which the changes are completed and these files are now ready to be committed.

You can manually stage each file one by one or only some of the files by clicking on the + icon after that file name as shown below:-


Once you've marked even a single file as staged, you can see the staged files under the Staged Changes heading and unstaged files under the Changes heading in VSCode as shown below:-


If you want to stage all the files at once, click on the + icon on the Changes heading as shown below:-


Once all your files are staged, the next step is to commit these files. In order to commit the files you need to specify a Commit Message. As you can see in the below image, you can specify a Commit Message in the message box in VSCode and click on the right (tick) icon to make a commit.


As you can see in the above image, I have specified a commit message as Initial Commit as it's the first time I am committing all the changes to git. You can give any commit message of your choice. Once you've committed all the files, your git changes sidebar will become empty as there is no further change made by you after the last commit.


After committing, if you do even a single change, your git bar will show you that file as Modified and you need to stage and commit that file again to mark the change as done.


As you can see in the above image, I have removed opening brace { from my setRequestMap() method and as I saved this file, it's specified as modified by the git in sidebar. After I am done with all the changes, I need to follow the same procedure as we did above to stage and commit the file. You can click on the filename in the git sidebar to review the change you've done as shown below:-


You can revert one or all the changes by clicking on the Undo icon which says (Discard Changes), on the left of the + icon for single file as shown in the above image or it'll show Discard All Changes if you see on the Changes heading.

Creating a GitHub repository

Now, we've done our first commit locally, it's time to create a new GitHub repository and push our changes here. To do that, first create an account on https://github.com/ 

After you created an account and you're logged in on github, the next step is to create a new repository. Go to the top menu bar and click on the + icon there and choose New repository as shown below:-


You'll see a new page as shown below:-


As you can see in the above image, first of  all you need to add a repository name, then you can give a description of your choice. After that you need to specify if your repository is public or private.

Public Repository:- Visible to everyone. Anyone can have a look at the code, clone your repository or submit a pull request.

Private Repository:- Visible only to you and the collaborators. You can invite people to collaborate on a private repository on github and they'll have access to this repository.

We don't need to initialize  this repository with a README as our project in VSCode already has a readme file as shown in the below image, so keep it unchecked.


Click on the Create Repository button to create a new repository as shown below:-


Once a new repository is created you'll be taken to a new screen as you can see in the below image:-


As you can see in the above image, I have a HTTPS URL automatically generated which is:- https://github.com/rahulmalhotra/ci-cd-tutorial.git

Adding origin to local repository in VSCode

Our next step is to tell VSCode git repository that it has to push the changes to this repository URL that we got from GitHub. So, we need to specify a remote server by giving this URL to our local git repo. In order to do that, open the terminal in your VSCode and execute the below command:-

git remote add origin <YOUR-REPOSITORY-URL>

As you can see in the below image, I have given my repo URL that I got from github after the git remote add origin command. This will basically tell my local git that this is the remote origin (server url with the name or alias origin) where I am going to push my code. You can also run a git remote -v  command to verify the remote URLs as shown below:-


I have also executed git status command to check the status and make sure that everything is clean and ready to be pushed.

Pushing our changes to GitHub

To push your changes, you need to execute the git push command from your terminal as shown below:-


As you can see above, as I executed git push I got a message that this branch has no upstream branch set. This message basically means that we haven't mapped our local git branch to the git branch on github server. By default, when you create a new git repo. You have a master branch automatically created. Similarly, on github when we created a new repository, a master branch is automatically created. But our next task is to tell git that you need to push our code in the local master branch to the remote master branch on github. In order to do that execute the command as specified by git in the above image which is:-

git push --set-upstream origin master

The above command will tell git to set the upstream (remote) branch as master for the current local branch which is also master by default and push the code. The shortcut for the above command is git push -u origin master where -u stands for --set-upstream


As you can see above, as I executed this command, the command asked for my github username and password that I entered and everything is pushed onto my github repository and I got a message that Branch master set up to track remote branch master from origin.

If you now go to your github repository and refresh that page, you can see that the code is pushed and is available on your github repository as shown below:-



Note:- Any empty folders in your project are automatically not tracked by git and will not be pushed to your github repository as well.

You can also push to your github repository by using the push option in VSCode as shown below, but make sure that you've set the remote origin first which is a one time effort that we did above.


Now it's your time. Make some changes, commit them and push them again to GitHub. Explore your commits in the GitHub repository and see what information you can see from there. You can have a look at the CI/CD Tutorial github repository that I used in this tutorial by clicking here.

Tired of reading or just scrolled down, don't worry, you can watch the video too.


That's all for this tutorial everyone, If you liked it, make sure to share it in your network and let me know your feedback in the comments down below.

Happy Trailblazing..!!

Saturday, 30 May 2020

Getting Started with Scratch Orgs | DevHub | Link VSCode project to a New Scratch Org

Hello Trailblazers,

In this post we're going to learn how we can enable devhub to create a scratch org and we'll also create a new VSCode project and link it with scratch org. Let's begin.

Enabling DevHub

In order to enable DevHub in your developer edition / trial / production org / business org, follow the below steps:-

1. Login as a System Administrator

2. Go to Setup and search for DevHub

3. You'll see a screen as shown below:-