Learning Salesforce Lightning Application Development
eBook - ePub

Learning Salesforce Lightning Application Development

Build and test Lightning Components for Salesforce Lightning Experience using Salesforce DX

  1. 458 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Learning Salesforce Lightning Application Development

Build and test Lightning Components for Salesforce Lightning Experience using Salesforce DX

About this book

Build, design, and style beautiful and informative applications on the Salesforce Lightning platform

Key Features

  • Build and Test Lightning Components that enhance application usability and adaptability
  • Apply Security Best Practices to your Custom Lightning Components
  • Design Lightning Components for Salesforce UIs such as Lightning Pages, Salesforce 1 Application, Communities, and more.

Book Description

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.

What you will learn

  • Understand Lightning Components architecture
  • Learn Locker security best practices
  • Debug and Improve performance of your Lightning Components
  • Use third-party libraries along with Lightning Component Framework
  • Learn how to publish Lightning Components on AppExchange
  • Use Lightning Out to take your Lightning Components outside the Salesforce platform

Who this book is for

This book is for Salesforce developers or developers from other platforms who are familiar with HTML, CSS, and JavaScript and want to build and test Salesforce Lightning components. No knowledge of Salesforce Lightning is required.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Year
2018
Print ISBN
9781787124677
eBook ISBN
9781787122314

Using External JavaScript Libraries in Lightning Components

Lightning Component framework has a rich set of JavaScript APIs that you can use to build client-side logic. However, there are a lot of open source libraries and frameworks that provide rich functionalities but can take a considerable amount of effort to rewrite using Lightning Component framework's native JavaScript APIs. One example of such a situation is if you are looking to build charts with Salesforce data, then building all the CSS and client-side JavaScript from scratch can consume a lot of time. Instead, you can import libraries such as ChartJs (https://www.ChartJs.Org/), HighCharts (https://www.highcharts.com/), or D3 (https://github.com/d3/d3/wiki/Gallery) to meet charting requirements with minimal code and without having to engineer everything from scratch.
Another example is using libraries such as jQuery to make client-side HTTP callouts. Similarly, if you already have a single-page application built using frameworks such as React or Angular, you can use the Lightning:container component to securely host your single-page application. Not all open source JavaScript libraries will be compatible with Lightning Components because of the Salesforce Locker Service that is in place for Lightning Components, to provide additional security. Therefore some libraries may require some manipulations before you can get them working under Locker Service.
The aim of this chapter is to show how to integrate external third-party libraries inside Lightning Components and test to make sure they work under Locker Service. We will be taking some well known third-party libraries such as jQuery, ChartJs, MomentJs, and many more to demonstrate the approach of using external libraries inside Lightning Components.
In this chapter, we will cover the following topics:
  • Using third-party JavaScript libraries in Lightning Components
  • Using the ltng:require tag
  • Creating a Locker Service-compliant JavaScript bundle using webpack
  • Examples of building custom components using ChartJs and MomentJs
  • Rendering a React application in a Lightning Component using a Lightning:container

Third-party JavaScript libraries in Lightning Components

Salesforce Lightning Component framework provides the ltng:require tag, which allows you to add one or more JavaScript files referenced from Salesforce static resources to Lightning Components. When you use the ltng:require tag, the JavaScript loaded has the ability to manipulate the DOM within the component's boundaries.
In this section, we will take a third-party JavaScript library called flipclock.js to build a Lightning Component that displays a flipclock. Note that flipclock.js is completely compatible with locker and hence we do not need any modifications to the original library source code. Later, in the Creating a Locker Service-compliant JavaScript bundle using webpack section, we will take an example where libraries are not compatible with locker and understand the general process to make them compatible with locker.
Before we deep dive into its usage, let's look at some of the attributes and events provided by the ltng:require tag.

Attributes

The following table shows the definition of each of the attributes available on the ltng:require component:
Attribute name Attribute type Description
body Component[]
The body of the component. In markup, this is everything in the body of the tag.
scripts String[]
The set of scripts that will be loaded in dependency order.
styles String[]
The set of style sheets that will be loaded in dependency order.

Events

The following table shows the definition of each of the events available on the ltng:require component:
Event Name
Event Type
Description
afterScriptsLoaded
COMPONENT
Fired when ltng:require has loaded all scripts listed in ltng:require.scripts
beforeLoadingResources
COMPONENT
Fired before ltng:require starts loading resources

Integrating a third-party library into Lightning Components

In this section, we will take a third-party JavaScript library, flipclock.js (http://FlipClock.js.com/), and build a Lightning Component that displays a clock and can be used as a timer.
The example that we will be using to build a Lightning Component is shown in the following code snippet:
<html>
<head>
<link rel="stylesheet" href="../compiled/flipclock.css">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="../compiled/flipclock.js"></script>
</head>
<body>
<div class="clock" style="margin:2em;"></div>

<script type="text/javascript">
var clock;

$(document).ready(function() {
clock = $('.clock').FlipClock({
clockFace: 'TwentyFourHourClock'
});
});
</script>

</body>
</html>

We are going to approach this step by step, and these steps apply to integrating any third-party libraries into a Lightning Component:
  1. Create a static resource hosting a third-party library: The first step is to download the library to your local machine and upload it to static resource. Note that due to the Content Security Policy, you cannot use JavaScript hosted on CDN inside Lightning Components and it is always recommended to upload to static resource. Any dependent JavaScript should be referred to from the static resource and can be loaded in order. The scripts attribute allows us to load multiple JavaScript files in order. In our case, the flipclock.js requires the jQuery library to be loaded beforehand. Also, it is recommended to use a zipped folder that can hold JavaScript and CSS assets. For this project, download the ZIP file that needs to be uploaded from static resource available at https://github.com/PacktPublishing/Learning-Salesforce- Lightning-Application-Development/blob/master/chapter7/libraries/flipclock.zip.
  1. Use the ltng:require tag and...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. PacktPub.com
  4. Foreword
  5. Contributors
  6. Preface
  7. Introduction to the Lightning Component Framework
  8. Exploring Salesforce DX
  9. Lightning Component Building Blocks
  10. The Lightning JavaScript API
  11. Events in the Lightning Component Framework
  12. Lightning Data Service and Base Components
  13. Using External JavaScript Libraries in Lightning Components
  14. Debugging Lightning Components
  15. Performance Tuning Your Lightning Component
  16. Taking Lightning Components out of Salesforce Using Lightning Out
  17. Lightning Flows
  18. Making Components Available for Salesforce Mobile and Communities
  19. Lightning Navigation and Lightning Console APIs
  20. Unit Testing Lightning Components
  21. Publishing Lightning Components on AppExchange
  22. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Learning Salesforce Lightning Application Development by Mohith Shrivastava in PDF and/or ePUB format, as well as other popular books in Business & Business Intelligence. We have over one million books available in our catalogue for you to explore.