Skip to main content

Posts

Showing posts with the label LWC

Capture Real time data using CDC(Change Data Capture) in Salesforce | SF Fact #05

Change Data Capture (CDC) enables receiving near-real-time updates for Salesforce records and synchronizing them with an external data store. CDC publishes change events that reflect modifications to Salesforce records, including new records, updates, deletions, and undeletions. These events can be subscribed to in a Lightning Web Component (LWC) using the Emp API. To meet the business requirement of creating a task whenever a user manually changes an opportunity's status to "Closed Won," use CDC events and a generic LWC on the opportunity record page. This solution avoids the need for Apex triggers or record-triggered flows. How to enable CDC? Go to setup Search Change Data Capture Add Entities The  lightning/empApi  module provides access to methods for subscribing to a streaming channel and listening to event messages. All streaming channels are supported, including channels for platform events, PushTopic events, generic events, and Change Data Capture events. This co...

How to get related records without using Apex?

getRelatedListRecords You can utilize this wire adapter to access RelatedList records. Related lists present information and links to records linked with a particular record. For instance, an account might have related lists for contacts, cases, notes, or files. Demo Code: import  {  LightningElement , wire, api }  from   'lwc' ; import  { getRelatedListRecords }  from   'lightning/uiRelatedListApi' ; export   default   class   Acc   extends   LightningElement  {     error;   records;       @ wire(getRelatedListRecords, {     parentRecordId:  '0015g00000DMcjgAAD' ,     relatedListId:  'Contacts' ,     fields: [ 'Contact.Name' , 'Contact.Id' ],     sortBy: [ 'Contact.Name' ]   })   listInfo({ error, data })...

Determine the execution context in apex

      The Quiddity Enum stands out as a highly valuable but often overlooked feature, offering one of the most effective means to grasp the context of Apex execution. Leveraging Quiddity allows us to discern whether an Apex method is invoked from Lightning Web Components (LWC), Aura, or an Anonymous context. Explore the comprehensive documentation linked below to discover the full range of contexts supported by Quiddity. Below is the Example of Quiddity. public List<Account> getAccountsWithQuiddityGuard () {       List<Account> accounts = new List<Account>();               public static List<Quiddity> allowedQuiddities = new List<Quiddity>{              Quiddity.QUEUEABLE,              Quiddity.BATCH_APEX,      ...

LWC Enhancements for Developers

  The Spring '23 release brings an abundance of exciting new features. Among these are enhancements to Lightning Web Components (LWCs) that aim to boost productivity, enhance security, and provide other useful utilities. These improvements facilitate debugging of LWC wired properties, enable synchronized component data without the need for page refreshes, introduce enhanced security layers for both LWC and Aura components, and offer additional tools for improved component testing. In this blog post, we will delve into the details of these updates. View debug information for your wired properties Inspecting Wired Properties with Debug Information Starting from Spring '23, debugging wired properties and methods becomes more straightforward through custom formatters in the Chrome debugger. Previously, developers had to use a wired function to retrieve deconstructed data and error properties for inspection. This new feature eliminates the need for rewriting wired properties and sea...

Shallow Clone Vs Deep Clone in LWC !!

  Are you acquainted with the concept of shallow and deep cloning within Lightning Web Components (LWC)?  Shallow cloning involves crafting a fresh object that retains the same reference as the original, whereas deep cloning entails c rafting a novel object with an entirely new reference . 👉 Why does this matter? Well, imagine having an object with nested attributes, and you wish to modify one of these attributes without impacting the original object. Opting for shallow cloning means that any adjustments made to the nested attribute will likewise manifest in the original object. However, by embracing deep cloning, you can alter the nested attribute without influencing the source object. 💻 When working with LWC, you can utilize the spread operator to execute shallow cloning, and resort to the JSON.parse/JSON.stringify technique to achieve deep cloning. 👨‍💻 Grasping the distinction between shallow and deep cloning is crucial for ensuring accurate object updates, while side...

Generate File Download URL Using LWC

  Introducing generateUrl for Lightning Web Components. Easily generate and return a URL for downloading files in Experience Cloud. With the generateUrl function, you can retrieve a URL for downloading files within your Lightning Web Runtime (LWR) site. Syntax: import { generateUrl } from "lightning/fileDownload"; const url = generateUrl(recordId); window.open(url); Parameters: recordID (Required): The record ID of the file (ContentDocument, ContentVersion, Attachment, or Document) you want to download. Returns: A URL that allows you to download the specified file. Usage: Authenticated users can download files they have proper access to. Guest users can download ContentDocument files only if they have access via Library membership. Sample Code: import { LightningElement } from "lwc"; import { generateUrl } from "lightning/fileDownload"; export default class Download extends LightningElement {     recordId;     url;     handleClick() {     ...

Enable reactivity in lwc:spread (LWC)

With the introduction of Salesforce Summer '23 release, a new feature for LWC components called lwc:spread became available. This feature enables us to spread properties on child components. Although the documentation provides instructions on its usage, ensuring the spread feature's reactivity is essential to fully leverage its capabilities. In this article, we will delve into examples of a parent component and a nested child component to grasp how to achieve reactivity for maximum usability. The lwc:spread directive allows accepting a single object with key-value pairs, where the keys represent property names. In the example below, we demonstrate how to use this feature to spread properties on child components: <!-- app.html --> <template>     <c-child lwc:spread={childProps}></c-child> </template> In this case, the parent component sets an object called "childProps" with properties "name" and "country" having values...