Posts

Showing posts with the label Lightning Web Component

Salesforce Lightning empAPI Module - Test Platform, CDC Events

Image
  Hello Trailblazers, In this blog I have explained use of EMP API which is used to subscribe for events. You can create Lightning Component which uses this EMP API for subscribing to various streaming channels such as Platform Events, Change Data Capture Events, Generic Events. We can use this implementation for testing Platform Events or Change Data Capture events in local environment. Lightning/empApi module has below methods which are used for implementing events subscription.  Method Name    Parameter Name  Description  subscribe    Subscribes to the streaming channel, this gives subscription object which we use to unsubscribe later.    onMessageCallback  Callback function which is invoked whenever an event is received    repla...

How to make HTTP callout from LWC

Image
Hello Trailblazers, In this blog we are going discuss about HTTP callouts from Client-side controller in LWC. In Aura components we have Apex controller with AuraEnabled method which have code for HTTP callout in it. We call this Apex method on execution of some action and then send the response back to Aura component for processing. But with Lightning Web Components we can easily make callout from Javascript itself using fetch method. If you are not familiar with fetch method then please checkout this link . fetch method primarily takes 2 parameters as input which are endpoint and information about request which includes method type, header information , body of the request all in JSON format. fetch(endpont, { REQUEST_INFO}).then((response => response.json())).then((responseData) => {PROCESS_responseData_HERE}); Let’s start with the implementation. I am going to use Data Faker Heroku app for demonstration. In this example I will be focusing on getting data from third party so ...

Generic Custom Lookup Lightning Web Component

Hello Trailblazers,   In this blog I have created generic lookup component using LWC which can be used directly without changing single line of code. You just have to pass object name, fields to be retrieved and fieldname on which search operation should happen while using this component along with event handler method, that’s it you are ready to use record captured in lookup field. Which makes it available for use multiple times in single component.    This example contains below main  components :   1.        GenericLookup   – Apex class for querying records   2.        genericLookup   - LWC Main component - This you will be using as per your need   3.        recordListItem   - LWC to render suggested records   First lets  have a look at GenericLookup class Now create  recordListItem  component This component is...