Skip to content
Lightning Web Components

How to do polling in LWC?

July 1, 2025

How to do polling in LWC? Polling means repeatedly calling a data source at set intervals—typically used when an API might fail temporarily or to continuously check for updates so that the latest information can be displayed. 

Before implementing polling, there are a few things to consider: 

  • What are we polling?
  • How many times do we want to poll?
  • Under what conditions should polling stop? 

In this article, we will learn how to implement polling for an Integration Procedure (IP) in LWC. Depending on your needs, you can use this approach to call a DataRaptor, API, or any other service. 

We will call an Integration Procedure, receive data in response, and display it in a lightning-dataTable within LWC. We will set-up the polling to run 10 times and any changes in the object data will be automatically reflected in the table during those polling intervals. 

Also Read: Vlocity Environment Variable Guide

Before starting our implementation 

Make sure you have IP which will return data and that IP we will call in LWC. As in the image below, here is our IP and it is returning Account Details. 

to do polling in LWC

This is the data returned by IP which will show on screen 

polling in LWC

For now, we will create a variable intervalId, which will be used to clear the setInterval, and a variable polling counter, which will increment by 1 with every polling attempt. 

In the connectedCallback, we will call our invokeIp function to execute the IP call every 5 seconds. 

We are using JavaScript’s built-in setInterval method for polling the IP. Based on certain conditions, we can stop the polling. 

To stop the polling, we simply need to clear the interval using intervalId.

export default class Checking extends LightningElement { 

   intervalId; 

   pollingCounter=0; 

   connectedCallback() 

       { 

         this.intervalId=  setInterval(()=>{ 

                this.invokeIP(); 

           },5000) 

       } 

 

   invokeIP(){ 

       if(this.pollingCounter<10){ 

           this.handleIPCall(); 

           this.pollingCounter++; 

       } 

       else{ 

           clearInterval(this.intervalId); 

       } 

   } 

   handleIPCall(){ 

       const params={ 

           input: '{}', 

           sClassName: "omnistudio.IntegrationProcedureService", 

           sMethodName: "testing_PoolingIP", 

           options: '{}', 

       } 

       this.omniRemoteCall(params,true).then(response => { 

          console.log("Integration Procedure Result: ", this.data); 

       }).catch(error => { 

          console.error("Error calling Integration Procedure: ", error); 

       }); 

   } 

} 

Now, we will display the IP response data in a Lightning datatable. Let’s add the code for the Lightning datatable in the LWC. 

For the datatable, we need both the column definitions and the table data. 

We will prepare the column configuration and assign the IP response data to a data variable, which will be used in the HTML part of the LWC. 

import { LightningElement,track } from 'lwc'; 

import { OmniscriptBaseMixin } from "omnistudio/omniscriptBaseMixin"; 

const columns = [ 

   { label: 'Account Name', fieldName: 'accountName' }, 

   { label: 'Website', fieldName: 'website', type: 'url' }, 

   { label: 'Phone', fieldName: 'phone', type: 'phone' }, 

   { label: 'Number of Employee', fieldName: 'numberOfEmployees' } 

]; 

export default class Checking extends OmniscriptBaseMixin(LightningElement) { 

   intervalId; 

   @track data; 

   columns = columns; 

   pollingCounter=0; 

   connectedCallback() 

       { 

         this.intervalId=  setInterval(()=>{ 

                this.invokeIP(); 

           },5000) 

       } 

   invokeIP(){ 

       if(this.pollingCounter<10){ 

           this.handleIPCall(); 

           this.pollingCounter++; 

       } 

       else{ 

           clearInterval(this.intervalId); 

       } 

   } 

   handleIPCall(){ 

       const params={ 

           input: '{}', 

           sClassName: "omnistudio.IntegrationProcedureService", 

           sMethodName: "testing_PoolingIP", 

           options: '{}', 

       } 

       this.omniRemoteCall(params,true).then(response => { 

           this.data=response.result.IPResult; 

 

          console.log("Integration Procedure Result: ", this.data); 

       }).catch(error => { 

          console.error("Error calling Integration Procedure: ", error); 

       }); 

   } 

} 

HTML of the LWC where we are using the lightning data table component and passing attributes, columns, data.

<template> 

   <div style="height: 300px;"> 

       <lightning-datatable 

               key-field="id" 

               data={data} 

               columns={columns}> 

       </lightning-datatable> 

   </div> 

</template> 

Now our table look like as shown below 

To check whether our polling is working or not, there are two ways: 

  1. Open the Network tab in your browser’s developer tools and observe that requests are being sent to our IP 10 times. 
  1. While polling is in progress, you can modify the Account (or other object) data using Salesforce Inspector and verify in the datatable whether your changes are reflected. While polling is happening Ip will return updated data.

Keep Reading

Related Articles and Resources

Salesforce Revenue Cloud vs Industries CPQ
July 11, 2025

Salesforce Revenue Cloud vs Industries CPQ

This comparison helps team choose the right Salesforce...

List Merge using Datamapper Formula
November 16, 2024

List Merge using Datamapper Formula

Suppose we have 2 lists in our output json but we want it...

Unable to get the Response from Integration Procedure into FlexCard data ?
November 10, 2024

Unable to get the Response from Integration Procedure into FlexCard data ?

There could be a scenario where you make a call to the...

What are Governor Limits in Salesforce?
October 29, 2025

What are Governor Limits in Salesforce?

If you’ve built on Salesforce for even a day, you’ll hit...

SetUp Rules in Salesforce Revenue Cloud Advanced (RCA)
October 2, 2025

SetUp Rules in Salesforce Revenue Cloud Advanced (RCA)

If you’ve ever wrestled with product bundles, discounts,...

Ultimate Salesforce Agentforce Guide: Your Complete Expert Resource
October 11, 2025

Ultimate Salesforce Agentforce Guide: Your Complete Expert Resource

Salesforce Agentforce marks the next big leap in AI,...