Book Image

Learning Salesforce Lightning Application Development

By : Mohit Shrivatsava
Book Image

Learning Salesforce Lightning Application Development

By: Mohit Shrivatsava

Overview of this book

Built on the Salesforce App Cloud, the new Salesforce Lightning Experience combines three major components: Lightning Design System, Lightning App Builder, and Lightning Components, to provide an enhanced user experience. This book will enable you to quickly create modern, enterprise apps with Lightning Component Framework. You will start by building simple Lightning Components and understanding the Lightning Components architecture. The chapters cover the basics of Lightning Component Framework semantics and syntax, the security features provided by Locker Service, and use of third-party libraries inside Lightning Components. The later chapters focus on debugging, performance tuning, testing using Lightning Testing Services, and how to publish Lightning Components on Salesforce AppExchange.
Table of Contents (22 chapters)
Title Page
PacktPub.com
Foreword
Contributors
Preface
Index

Preface

The Salesforce Lightning platform is widely used today in a number of Fortune 500 companies for building applications that are used in sales, services, marketing, collaboration, and various other business areas. Salesforce provides the most popular Customer Relationship Management (CRM) system, and the demand for Salesforce developers and consultants is increasing every year. Applications built on top of the Lighting platform are cloud based, secure, and require no on-premises software installation. 

Salesforce Lightning Experience is a redesigned user interface that allows users to be more productive and innovative. Lightning Experience comprises pages and layouts that can be customized using Lightning Application Builder (a drag-and-drop interface that allows administrators to build pages by dropping various components) and Lightning Components. Salesforce provides out-of-the-box Lightning components that administrators can leverage for most business needs. However, not all user interface challenges can be solved with these out-of-box components. The Lightning Components Framework allows Salesforce developers to build custom Lightning components. A Lightning component is made up of HTML (markup) and JavaScript (secured using Salesforce LockerService) and forms a component bundle that can be placed in Salesforce Lightning Experience, Salesforce Communities, Salesforce Mobile App, Salesforce for Outlook, Chatter Publisher, and other Salesforce interfaces.

Salesforce DX allows developers to adopt source-driven development techniques. Salesforce DX simplifies developer workflows on the platform and helps to build and iterate Salesforce applications faster. Salesforce DX provides a command line interface (CLI) tool that simplifies setting up the developer environment for development, debugging, unit testing, and deploying Salesforce applications.

This book will teach you how to build custom Lightning components by using the Lightning Components Framework and leveraging Salesforce DX CLI commands. In this book, we cover the fundamentals and capabilities of the framework. The end goal of this book is to provide Salesforce developers with enough information so that they can start designing and building components on their own to meet their custom component needs.

 

Who this book is for

The target audience for this book includes beginner, intermediate, and advanced Salesforce developers and architects who want to fully understand the capabilities of the Lightning Components Framework and learn about application development on the Salesforce platform.

This book can also be used by JavaScript frontend developers who are familiar with JavaScript and want to understand the capabilities and boundaries of the Lightning Components Framework. The book also covers the integration capabilities of the framework with other open source JavaScript libraries and how to take Lightning components built on the platform to outside world.

What this book covers

Chapter 1, Introduction to the Lightning Components Framework, introduces you to the basics of the Lightning Components architecture and tells you why you should learn about the Lightning Components Framework. The chapter also covers Lightning Experience UI capabilities and where in the Lightning Experience you can leverage custom Lightning components to customize.

Chapter 2, Exploring Salesforce DX, covers basics of the Salesforce DX CLI capabilities and commands. The chapter focuses on how to leverage Salesforce DX to create a source-driven development workflow on the platform. You will learn how to use Salesforce DX to create Salesforce applications.

Chapter 3, Lightning Component Building Blocks, teaches you how to build a custom Lightning component. This chapter covers how to write component markup, JavaScript client-side controllers and helper functions, server-side Apex code that client-side helper functions can talk to, and Lightning Base components to create layouts.

Chapter 4, Lightning JavaScript API, covers the native APIs that are provided by the framework and the LockerService security model for the components. This chapter also talks about differences between the native JavaScript APIs and the APIs available under LockerService.

Chapter 5, Events in the Lightning Components Framework, teaches you the syntax for creating and firing application and component events. The chapter also covers various intercommunication patterns available in the framework for passing data between components.

 

Chapter 6, Lightning Data Service and Base Components, covers the syntax and capabilities of Lightning Data Service and how it simplifies fetching context data, as well as how it enables you to create, read, edit, and delete records when it comes to contextual data. You will also explore how the Lightning Data Service can make custom components react to data changes in the UI. This chapter also teaches you how to work with Salesforce-provided base components.

Chapter 7, Using External JavaScript Libraries in Lightning Components, covers how you can integrate third-party libraries, such as Chart.js, Moment.js, and ReactJS with the Lightning Components Framework. You will also learn about the debugging procedure in the case of a library not working under LockerService, and you'll discover how to use open source JavaScript bundlers, such as WebPack, to make them LockerService compatible.

Chapter 8, Debugging Lightning Components, teaches you about the debugging techniques for client-side JavaScript controllers and helpers using Chrome Developer Tools, and debugging techniques for Apex using the new Apex Replay Debugger.

Chapter 9, Performance Tuning Your Lightning Components, covers how you can improve the performance of your Lightning components with techniques such as using storable actions, platform caching, and paginating data rows that are returned from the server. You will learn about the Chrome extensions and plugins available for figuring performance bottlenecks.

Chapter 10, Taking Lightning Components outside Salesforce Using Lightning Out, teaches you how to work with the Lightning Out technology. You will learn about the steps and processes required to take your Lightning components outside the Salesforce platform.

Chapter 11, Lightning Flows, teaches you how to use Lightning components with the Salesforce Flow builder. You will learn about how components can pass data to flows and how you can embed flows inside Lightning components.

Chapter 12, Making Components Available for Salesforce Mobile and Communities, teaches how to use Lightning components in Salesforce mobile applications (Salesforce1), and Salesforce Community Builder. We will learn how to customize communities  using custom theme layouts and custom navigation. You will also learn how to override profile menus and create your own templates. 

Chapter 13, Lightning Navigation and Lightning Console APIs, covers how to work with the Navigation API, the Workspace API, and the Messaging API for the Utility Bar component. The chapter also teaches you about the options available for customizing components in Salesforce Console.

 

Chapter 14, Unit Testing Lightning Components, teaches you how to write unit tests for Lightning components using the Lightning Testing Service. You will learn about Jasmine and how to leverage Jasmine with the Lightning Testing Service to write unit tests for the custom Lightning components.

Chapter 15, Publishing Lightning Components on AppExchange, teaches you how to publish components on Salesforce AppExchange so that components can be installed in multiple Salesforce instances.

To get the most out of this book

The book assumes that the reader has had some exposure to programming. The book also assumes that you are familiar with the Salesforce Apex programming language, JavaScript fundamentals (especially the concepts of variables, callbacks, and promises), HTML, and CSS. The book expects that you are familiar with Salesforce administration capabilities, such as creating objects and fields, and navigating through Salesforce.

To get most out of the book, sign up for a promotional Salesforce Org with Salesforce DX enabled at https://developer.Salesforce.com/promotions/Orgs/dx-signup , or a developer Org at https://developer.Salesforce.com/signup, and try all the code snippets discussed in the book by creating scratch Orgs for every chapter. Instructions for creating scratch Orgs, with the accompanying code, can be found in the following GitHub repository: https://github.com/PacktPublishing/Learning-Salesforce-Lightning-Application-Development.

The book uses the following software, all of which is freely available:

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

 

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learning-Salesforce-Lightning-Application-Development. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/LearningSalesforceLightningApplicationDevelopment_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "To override NewEdit, or View, the Lightning component must implement the Lightning:actionOverride interface."

A block of code is set as follows:

function StringUtils() {};

StringUtils.prototype.concatenate = function(str1,str2) {
  return str1.concat(str2);
};

StringUtils.prototype.camelcase = function(string) {
  string = string.toLowerCase().replace(/(?:(^.)|([-_\s]+.))/g, function(match) {
      return match.charAt(match.length-1).toUpperCase();
  });
  return string.charAt(0).toLowerCase() + string.substring(1);
};

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

describe("when string operations are performed", function(){

      //Spec for Concatenation operation
      it("should be able to concatenate hello and world", function() {
 expect(stringUtil.concatenate('Hello','World')).toEqual('HelloWorld');
      });

      //Spec for camelcase operation
      it("should be able to camelcase", function() {
          expect(stringUtil.camelcase('hello-world')).toEqual('helloWorld');
      });

      //Spec for capitalizeFirstLetter
      it("should be able to capitalize First Letter", function() {
          expect(stringUtil.capitalizeFirstLetter('world')).toEqual('World');
      }); 
  });

Any command-line input or output is written as follows:

sfdx force:lightning:test:run

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Once in the Setup menu, find App Manager from the search box. A new Lightning app can be created using the New Lightning App button."

 

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.