Posts

Showing posts from January, 2021

Communicating from the Child Component to the Parent Component in LWC

Communicating from the Child Component to the Parent Component in LWC In Lightning Web Components (LWC), communication between components is essential for building interactive applications. In this post, we’ll explore how to communicate from a child component to a parent component using events, illustrated with a real-time example. Step 1: Create the Parent Component First, let's create the parent component called parentComponent . This component will manage a counter that can be incremented or decremented through actions performed in the child component. 1. Update parentComponent.js Here's the JavaScript code for the parent component: import { LightningElement } from 'lwc' ; export default class Parentcomponent extends LightningElement { counter = 0 ; // Increase the counter value when the user clicks onClickAdd ( ) { this . counter ++; } // Decrease the counter value when the user clicks onClickSub ( ) { this . cou...

Common Types of Exceptions in Apex

What Do You Mean by Exception? An exception is an event that occurs during the execution of a program, disrupting the normal flow of the program's instructions. In Apex, you can utilize built-in exceptions or create your own custom exceptions. All exceptions share common methods and support built-in functionalities for returning error messages and exception types. Common Types of Exceptions in Apex Let's explore a few of these exceptions: In Salesforce Apex, exceptions are errors that disrupt the normal flow of code execution. Apex provides a variety of built-in exception classes to handle different error scenarios. Here are some common exceptions: DmlException : Occurs when there's an issue with a DML statement, such as inserting a record without required fields. ListException : Thrown when attempting to access an index that is out of bounds in a list. NullPointerException : Happens when trying to dereference a null object. QueryException : Arises from problems with SOQL ...

Aura Component Event Propagation in Salesforce

Component Event Propagation in Salesforce Understanding how events propagate through components in Salesforce's Aura framework is crucial for building interactive applications. Events move in two main phases: Capture and Bubble . Let's explore both phases in detail. Capture Phase During the Capture phase, the event travels from the application root down to the source component. Here’s what happens: Order of Invocation : Event handlers are triggered starting from the application root and moving down through the component hierarchy to the source component. Stopping Event Propagation : At any point during this phase, a handler can call stopPropagation() . This prevents the event from propagating further, meaning that any remaining handlers will not execute. Bubble Phase Once the event reaches the source component, the Bubble phase begins: Order of Invocation : The event now bubbles back upward, starting from the source component and moving back up to the application root. Stoppin...