Implement Infinite Scrolling for lightning-datatable

When to use wire vs Imperative approach to call Apex in Lightning Web Component

If you are thinking this post is about implementing infinite scrolling behavior for lightning-datatable component, then you only got half part right. Main purpose of this blog post is to compare side by side @wire vs Imperative way of calling Apex and decide which one to use when?

If you are looking for basics of LWC or how to use LWC in flow, Lightning Message Service, how to call Apex then follow this link.

In this post, you would learn

  • How to call Apex in LWC using @wire
  • How to call Apex in LWC by Imperative approach
  • How to call Apex on component load event equivalent to init in Aura
  • Why would you choose to call Apex either by @wire or Imperative Apex approach
  • How to bind wrapper class in Lightning-datatable component
  • How to enable infinite scrolling in Lightning-datatable by making server call
Continue reading “Implement Infinite Scrolling for lightning-datatable”

Using Custom Label in Lightning Web Components – LWC

Quick Code Snippet on how to use custom label in Lightning Web Components – LWC

Below is code snippet on using custom labels in Lightning Web Components.

Assume, we have custom label named welcomeText and exitText

In Javascript file of LWC, we have to follow below syntax

// CustomlabelExample.js
import { LightningElement } from 'lwc';
 
// Import custom labels
import welcomeText from '@salesforce/label/c.welcomeText';
import exitText from '@salesforce/label/c.exitText';


export default class CustomLabelExample extends LightningElement { 

    // Expose the labels to use in the template.
    label = {
        welcomeText,
        exitText
    };
}

Notice, how we imported label and used c. if there is no namespace.

import welcomeText from '@salesforce/label/c.welcomeText';
<!-- CustomlabelExample.html -->
<template>
    Hi , {label.welcomeText} !!! 
   <!-- some more code --> 
   Sorry to see you going, {label.exitText}
</template>

Reference :

Use Lightning Web Components in Flow

Endless limit for your Salesforce application by combining Flow with Lightning Web Components (LWC)

As part of Winter 20, we can embed Lightning Web Components in Flow. Imagine, endless possibilities for Rapid Application Development (RAD) and ease of maintaining application.

Few examples where this could come handy are like embedding lookup components (no more workaround), showing data table, capturing signature, slide shows and so on.

It’s time to jump into water. In this blog post, I would be creating Simple Lightning Web Component (LWC). This LWC Component would be able to get value from flow, pass value to flow, navigate to Next screen and hookup into flow validation engine to restrict next page navigation if there is error in LWC input.

Note : Read this blog post to learn how to embed Aura Component in Flow.

Continue reading “Use Lightning Web Components in Flow”

Event Handling between Aura, Lightning Web Components (LWC) and Visualforce

How to use Lightning Message Services for event handling between Lightning Web Components, Aura Components and Visualforce

Few months back, I wrote an article on how pub sub model can be used to communicate between Lightning Web Components. In that blog post, we used external library to pass event from child to Lightning Web Components.

Lightning Message Service

In Winter 20, Salesforce released Lightning Message Service which can be used to exchange data between Visualforce, Aura Component and Lightning Web Components. Unlike previous process, we don’t need to import any external library like pub or sub.

In this blog post, I would be creating Visualforce, Aura Component and Lightning Message Service and exchanging message between all of them using Lightning Message Service.

Continue reading “Event Handling between Aura, Lightning Web Components (LWC) and Visualforce”

Get Current User Id in Salesforce

How to get Current Logged in user Id in Apex, Visualforce, Lightning Component and Formula fields in Salesforce

Quick Code Snippets of how to get Current logged in user ids in Salesforce

Apex

System.debug('Current User Id - '+UserInfo.getUserId());

Visualforce

<apex:page>
  <h1>Visualforce Page</h1> 
   <p>UserId: {!$User.Id}</p>
   <p>User Email: {!$User.Email}</p>
</apex:page>

Aura Component

let currentUser = $A.get("$SObjectType.CurrentUser.Id");
Console.log(currentUser);

Lightning Web Components (LWC)

Using wire

import USER_ID from '@salesforce/user/Id';
import NAME_FIELD from '@salesforce/schema/User.Name';
import EMAIL_FIELD from '@salesforce/schema/User.Email';

Formula Fields

$User.Id