Tag: Lightning Migration services

Lightning Web Components : Best Practices to Enhance Performance
Lightning Platform, Salesforce

Lightning Web Components: Best Practices to Enhance Performance

There are many ways to improve lightning web component performance. Here, we are discussing some of the essential practices.

  • Data Caching

Application composition is a meaningful way used to build apps by assembling different components. But here is another problem, the independent nature of components leads them to make their own decisions that affect their overall performance. 

Suppose there are many components in the ecosystem that make their call to the server. The server is flooded with calls, creating massive traffic of incoming calls. The server should get a single call rather than many calls from the components.

Data caching improves performance by distributing the data among different components, which reduces the server load and response time.

The Lightning web component has in-built features for client-side caching.

  • Lightning Data Service

Salesforce uses Lightning data service to improve data flow between the components. 

It is responsible for managing records, fetching records from the server when requested. It also shares the records between the components when requested and stores the documents in a highly efficient client cache.

Lightning data service helps in executing these operations quickly:

  • Loading a record
  • Saving a record
  • Creating a record
  • Deleting a record
  • Record changes
  • Reported errors

  • Use Performance Tools for Improvement

Tools like “Chrome timeline inspector” and “Salesforce Lightning inspector” are for understanding performance issues.

Chrome timeline inspector:

The Chrome timeline inspector tool enables you to inspect the component attributes, profile performance of the components and navigates the component tree.

The extension helps to:

  • Identify bottlenecks in the performance.
  • Simulates error conditions or dropped action responses
  • Navigate the component roadmap in your app
  • Track the handling for one or more actions

Salesforce Lightning Inspector:

The Salesforce Lightning Inspector improves the Lightning Component development, giving access to data about the components and application.  

With the Salesforce Lightning Inspector :

– Easily navigate and inspect the structure of the components

– Identify performance bottlenecks 

– Faster debugging of server interactions by monitoring

– Inspect components and associated DOM elements

– Handling sequences and track firing of events

  • Data Retrieval

There are various available options for data retrieval from the server using lightning web components.

These things have to be kept in mind while optimizing server round trips.

  • Make sure there is no other option to get the data before making a server call.
  • Use the cache data or lightning data service wherever possible.
  • Use Javascript arrays that have built-in functions for sorting, filtering & finding values.
  • Don’t preload data that the user may never need for their use.

  • Component Instantiation

Showing every piece of tool and data on the screen is not considered a great practice. 

It impacts the performance of the application. 

Lightning Components are added to a page layout, which instantiates when the page is loaded.

The interaction design guidelines favor progressive disclosure.

As per Wikipedia

“Progressive disclosure is defined as an interaction design technique often used in human-computer interaction to help maintain the focus of a user’s attention by reducing clutter, confusion, and cognitive workload.

It improves usability by presenting only the minimum data required for the task at hand.”

These practices bring out the best performance from Lightning web components. We hope all the Salesforce Developers will enjoy reading and implementing them. 

CEPTES is a Salesforce Silver consulting partner that can guide you as your strategic partner to speed up the business value of your Salesforce.com investment through consultation, digitization, and innovation. If you are thinking of growing your business using the Salesforce platform, then get in touch; we are happy to help you.

ALSO READ: TOP 10 BENEFITS OF LIGHTNING WEB COMPONENT OVER AURA LIGHTNING COMPONENTS

Salesforce

How to Manage Dependency Injection within Salesforce

If you don’t know what Dependency Injection is, why it is required, which problem does it help us resolve, and how Dependency Injection is used in Salesforce, then don’t worry; by the end of this article, you will be clear of all your doubts.

Dependency InjectionWhat is Dependency Injection (DI)?

Dependency Injection is a design pattern that provides inversion of control; it is used for breaking tight coupling between 2 objects. It is an alternative approach to binding two objects loosely. 

Let us understand this with the help of an example.

Why is Dependency Injection required?

Let us consider the example of the client consuming the services provided by a server.

Typically, the server would be instantiated by the client as below:

Server s = new Service ();

s.Print();

Yet, the above code introduces a dependency between the Client and Server, and the client is tightly coupled with the server, as seen in the below diagram. 

You can see the implications of this dependency by trying to delete the Service, which is not possible as the client uses it.

So, what do you think are the issues with the above type of binding?

  1. The flexibility is reduced
  2. It is difficult to make changes
  3. It is not easy to reuse the code

DependencySo, we prefer to use Dependency Injection for flexibility, extensibility, and reusability of code.

Let us now see how Dependency Injection is managed in Salesforce;

In Salesforce, there are two types of dependencies possibilities.

  1. Introduced due to coding
  2. Dependency between metadata formed by using declarative tools (process, flow, layout, and actions)

Dependency injection helps in forming dependencies at runtime instead of explicitly during development. It aims to break the dependence between the calling code and how an instance is created. 

In the above example, we saw that the client had access to the Server implementation. The solution would be to invert the control, such that the client does not know about the server implementation details. 

The use of the “new” operator needs to be avoided to use Dependency injection, since the usage of a “new” operator requires packaging and deploying the Server implementation along with the client, resulting in loss of extensibility.

The goal of Dependency Injection is to eliminate the need for the calling code needing to know how an instance is obtained; it only needs to know how to use it. Through dependency injection, multiple different implementations could be packaged and deployed.

A dependency exists in the above example because the compiler needed to know the Service class of the client. 

The compiler needed to check whether the Service class compiles; the aim is to remove this dependency. This is possible if we load the Service class at runtime. An injector class would be required to load and provide the required service implementation class. 

The need for an Interface. To achieve loose coupling, we need to design the code to interact with an interface rather than an implementation. The implementation of the interface would vary from customer to customer. 

Dependency Injection uses configuration and code to dynamically determine the implementation used, thus decoupling dependencies from where they are used, as seen in the diagram.

Dependency managementTo Summarize

We saw what Dependency Injection is, the issues observed if Dependency injection is not used, the different types of Dependency Injection, and how to break down tight coupling and replace it with loose coupling using Dependency Injection within Salesforce.

The pros and cons of Dependency Injection are as below:

Pros: 

  1. Breaks the tight-coupling as it causes issues with reusing, updating, and maintaining the code.
  2. Adds support for many optional implementations that can be selected at runtime without code modifications.

Cons:

  1. Introduces complexity in the architecture as it is challenging to identify implementations corresponding to associated calls.
  2. Difficult to troubleshoot in case something breaks at execution. Delay in identifying runtime issues.

CEPTES is a Salesforce partner with 10+ years of ecosystem expertise & over 80% Salesforce certified consultants. We are widely accepted as a leader in delivering Salesforce Cloud (Sales Cloud, Service Cloud, Marketing Cloud, App Cloud, etc.), Salesforce Analytics, and Lightning Migration services to various industries and companies of different sizes & types.

If you are looking for Certified Salesforce consulting services, then contact us today!