By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
horizontal-light horizontal-dark
  • Home
  • Tutorials
    • Salesforce AI
    • Salesforce DevOps
    • Career
    • Errors
    • Interview Questions
    • Salesforce Integration
    • Salesforce Flow
  • Salesforce Tools
  • Apex Development
  • Lightning Web Components
  • Salesforce Admin
  • About
    • Privacy Policy
    • Disclaimer
    • Terms & Conditions
    • Contact
SalesforceCornerSalesforceCorner
Search
  • Home
  • Tutorials
    • Salesforce AI
    • Salesforce DevOps
    • Career
    • Errors
    • Interview Questions
    • Salesforce Integration
    • Salesforce Flow
  • Salesforce Tools
  • Apex Development
  • Lightning Web Components
  • Salesforce Admin
  • About
    • Privacy Policy
    • Disclaimer
    • Terms & Conditions
    • Contact
Follow US
Salesforce Corner » Lightning Web Components » RefreshApex in LWC: Keep Salesforce Data Updated in Real Time
Lightning Web Components

RefreshApex in LWC: Keep Salesforce Data Updated in Real Time

Master real-time Salesforce data refresh using refreshApex in Lightning Web Components.

Neha Panwar
By
Neha Panwar
ByNeha Panwar
Salesforce Developer and Technical Writer
Neha Panwar is a Salesforce developer and technical writer who creates practical learning resources for Salesforce administrators and developers. She specializes in Salesforce Administration, Apex, Lightning...
Follow:
- Salesforce Developer and Technical Writer
Last updated: 2026/06/21
Share
RefreshApex in LWC workflow
SHARE

Salesforce Lightning Web Components often display cached data for better performance. However, there are many situations where the displayed data becomes outdated after records are updated, inserted, or deleted.

This is where refreshApex() becomes extremely important.

The refreshApex() function allows developers to refresh wired Apex data without reloading the entire page. It helps Lightning Web Components display the latest Salesforce data in real time.

If you are learning Lightning Web Components, you should first understand these concepts before moving deeper into refreshApex:

Contents
What Is refreshApex() in LWC?Why refreshApex() Is ImportantHow refreshApex() WorksBasic Syntax of refreshApex()Simple refreshApex Example in LWCApex ControllerLWC JavaScriptLWC HTMLUnderstanding the Important PartrefreshApex After Imperative Apex CallsReal Example: Update Opportunity StageApex ControllerLWC JavaScriptrefreshApex with Wired PropertiesrefreshApex with Wired FunctionsReal-Time Salesforce UI Refresh ScenariorefreshApex vs Reloading the PageCommon refreshApex MistakesForgetting to Store Wired ResultUsing refreshApex Without @wireExcessive Refresh CallsrefreshApex with Platform EventsrefreshApex and Lightning Data ServiceBest Practices for refreshApex()Store the Wired Result ProperlyRefresh Only When NeededCombine with Imperative Apex CarefullyUse Async/AwaitShow Loading IndicatorsWhen Should You Use refreshApex()?When NOT to Use refreshApex()refreshApex vs notifyRecordUpdateAvailable()Real Enterprise Use CasesSales DashboardSupport ConsoleInventory SystemsApproval SystemsAI Monitoring DashboardsFinal ThoughtsRead more :

Salesforce @wire Decorator in LWC with Real Examples
How to Call Apex Imperatively in Salesforce LWC
Salesforce LWC Lifecycle Hooks Explained with Real Examples

What Is refreshApex() in LWC?

refreshApex() is a function provided by Salesforce that refreshes cached data returned from Apex methods wired using @wire.

It forces the component to fetch fresh data from the Salesforce server.

Without refreshApex(), users may continue seeing stale or outdated data inside Lightning components.

Why refreshApex() Is Important

Salesforce uses client-side caching for performance optimization.

For example:

  • Opportunity updated
  • Case status changed
  • Contact inserted
  • Records deleted

But the component UI may still show old data.

refreshApex() solves this problem by refreshing the wire service data.

This creates:

  • Better user experience
  • Real-time UI updates
  • Faster applications
  • Cleaner data synchronization

How refreshApex() Works

The overall flow looks like this:

  1. Apex method loads data using @wire
  2. Salesforce caches the response
  3. User updates records
  4. Data becomes stale
  5. refreshApex() is called
  6. Salesforce queries fresh data
  7. UI rerenders automatically

Salesforce refreshApex data refresh workflow in LWC

Basic Syntax of refreshApex()

import { refreshApex } from '@salesforce/apex';

Usage:

refreshApex(wiredResult);

The parameter passed to refreshApex() must be the complete wired result object.

Simple refreshApex Example in LWC

Apex Controller

public with sharing class AccountController {

@AuraEnabled(cacheable=true)
public static List<Account> getAccounts() {

return [
SELECT Id, Name
FROM Account
LIMIT 10
];
}
}

LWC JavaScript

import { LightningElement, wire } from 'lwc';

import getAccounts
from '@salesforce/apex/AccountController.getAccounts';

import { refreshApex }
from '@salesforce/apex';

export default class AccountList extends LightningElement {

accounts;

wiredAccountsResult;

@wire(getAccounts)
wiredAccounts(result) {

this.wiredAccountsResult = result;

if(result.data) {
this.accounts = result.data;
}
}

handleRefresh() {

refreshApex(this.wiredAccountsResult);
}
}

LWC HTML

<template>

<lightning-button
label="Refresh Data"
onclick={handleRefresh}>
</lightning-button>

<template for:each={accounts} for:item="acc">

<p key={acc.Id}>
{acc.Name}
</p>

</template>

</template>

Understanding the Important Part

This line is extremely important:

this.wiredAccountsResult = result;

Many beginners make mistakes here.

You must store the complete wire result object because refreshApex() needs it later.

refreshApex After Imperative Apex Calls

One of the most common real-world use cases is:

  • Update records using imperative Apex
  • Refresh UI using refreshApex()

This pattern is heavily used in enterprise Salesforce applications.

Also read: How to Call Apex Imperatively in Salesforce LWC

Real Example: Update Opportunity Stage

Apex Controller

public with sharing class OpportunityController {

@AuraEnabled(cacheable=true)
public static List<Opportunity> getOpportunities() {

return [
SELECT Id, Name, StageName
FROM Opportunity
LIMIT 10
];
}

@AuraEnabled
public static void closeOpportunities() {

List<Opportunity> opps = [
SELECT Id, StageName
FROM Opportunity
LIMIT 10
];

for(Opportunity opp : opps) {
opp.StageName = 'Closed Won';
}

update opps;
}
}

LWC JavaScript

import { LightningElement, wire }
from 'lwc';

import getOpportunities
from '@salesforce/apex/OpportunityController.getOpportunities';

import closeOpportunities
from '@salesforce/apex/OpportunityController.closeOpportunities';

import { refreshApex }
from '@salesforce/apex';

export default class OpportunityList extends LightningElement {

opportunities;

wiredOpportunityResult;

@wire(getOpportunities)
wiredOpps(result) {

this.wiredOpportunityResult = result;

if(result.data) {
this.opportunities = result.data;
}
}

async handleCloseWon() {

await closeOpportunities();

await refreshApex(this.wiredOpportunityResult);
}
}

This creates real-time UI synchronization after record updates.

Imperative Apex call with refreshApex in Salesforce LWC

refreshApex with Wired Properties

refreshApex() works perfectly with wired properties.

Example:

@wire(getAccounts)
accounts;

Refresh:

refreshApex(this.accounts);

refreshApex with Wired Functions

You can also use refreshApex() with wired functions.

Example:

wiredResult;

@wire(getAccounts)
wiredAccounts(result) {

this.wiredResult = result;
}

Then refresh:

refreshApex(this.wiredResult);

Real-Time Salesforce UI Refresh Scenario

Imagine a customer support dashboard.

Support agents:

  • Close cases
  • Update priorities
  • Assign owners

Without refreshApex():

Old data remains visible.

With refreshApex():

UI updates instantly.

This dramatically improves user experience.

refreshApex vs Reloading the Page

Many beginners refresh the entire browser page.

This is NOT recommended.

MethodPerformance
Browser RefreshSlow
refreshApex()Fast
Full ReloadBad UX
Partial Data RefreshBetter UX

refreshApex() is far more efficient.

Common refreshApex Mistakes

Forgetting to Store Wired Result

Wrong:

@wire(getAccounts)
accounts;

Then:

refreshApex(this.accounts.data);

This will not work properly.

Correct:

refreshApex(this.accounts);

Using refreshApex Without @wire

refreshApex() only refreshes wired Apex data.

It does not refresh normal variables automatically.

Excessive Refresh Calls

Avoid unnecessary refresh calls.

Too many server refreshes can create:

  • Performance issues
  • API overhead
  • Slow UI rendering

refreshApex with Platform Events

Advanced Salesforce projects often combine:

  • Platform Events
  • Streaming API
  • refreshApex()

This enables near real-time enterprise dashboards.

Example use cases:

  • Live support dashboards
  • Real-time sales tracking
  • Inventory systems
  • AI monitoring dashboards

Salesforce Platform Events with refreshApex real-time updates

refreshApex and Lightning Data Service

Salesforce also provides:

  • Lightning Data Service
  • notifyRecordUpdateAvailable()
  • RefreshView API

However, refreshApex() is mainly used for Apex wire service refresh scenarios.

Best Practices for refreshApex()

Store the Wired Result Properly

Always keep the full wire response object.

Refresh Only When Needed

Avoid unnecessary server calls.

Combine with Imperative Apex Carefully

This pattern is extremely common in enterprise Salesforce apps.

Also read: Salesforce Governor Limits with Real Examples and Best Practices

Use Async/Await

Cleaner syntax:

await refreshApex(this.wiredResult);

Show Loading Indicators

Use spinners while refreshing data.

Better UX improves application quality.

When Should You Use refreshApex()?

Use refreshApex() when:

  • Records update after DML
  • UI data becomes stale
  • Imperative Apex changes records
  • Real-time refresh is required
  • Wired Apex methods are used

When NOT to Use refreshApex()

Avoid using it:

  • For static data
  • Inside loops
  • After every click unnecessarily
  • Without wire service

refreshApex vs notifyRecordUpdateAvailable()

FeaturerefreshApexnotifyRecordUpdateAvailable
Works with Apex @wireYes
Works with LDSLimitedYes
Refreshes wired ApexYesNo
Common in custom Apex appsYesLess

Real Enterprise Use Cases

Sales Dashboard

Refresh opportunities after updates.

Support Console

Refresh cases after status changes.

Inventory Systems

Refresh stock levels instantly.

Approval Systems

Refresh approval queues automatically.

AI Monitoring Dashboards

Real-time Agentforce data refresh.

Also read: What Is Salesforce Agentforce? Complete Beginner Guide

Final Thoughts

refreshApex() is one of the most important Lightning Web Components concepts for building responsive Salesforce applications.

It helps developers keep Lightning components synchronized with Salesforce data without reloading pages.

Most enterprise Salesforce projects heavily rely on:

  • @wire
  • Imperative Apex
  • refreshApex()
  • Lightning Data Service

Together, these concepts create modern, high-performance Salesforce applications with real-time user experiences.

If you want to become a strong Salesforce LWC developer, mastering refreshApex() is absolutely essential.

Read more :

How to Call Apex Imperatively in Salesforce LWC
Salesforce LWC Lifecycle Hooks Explained with Real Examples
Salesforce Governor Limits with Real Examples and Best Practices
Queueable Apex in Salesforce for Beginners: Complete Async Processing Guide
Salesforce REST API Tutorial for Beginners with Real Integration Examples

TAGGED:Imperative Apexlightning web componentslwc tutorialrefreshApexsalesforce apexsalesforce developersalesforce lwcSalesforce UI RefreshWire Service
Share This Article
Facebook Email Print
ByNeha Panwar
Salesforce Developer and Technical Writer
Follow:
Neha Panwar is a Salesforce developer and technical writer who creates practical learning resources for Salesforce administrators and developers. She specializes in Salesforce Administration, Apex, Lightning Web Components (LWC), Flow, integrations, and automation. Through Salesforce Corner, she publishes step-by-step tutorials, coding guides, and real-world solutions designed to help readers understand Salesforce concepts and apply them in projects with confidence.
Leave a Comment Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest Post

Apex Trigger Automation Flow
Apex Triggers in Salesforce: A Complete Guide
Apex Development
how to create and use queues in salesforce
How to Create and Use Queues in Salesforce with Examples
Salesforce Admin
Salesforce Escalation Rules
Salesforce Escalation Rules: A Complete Guide
Salesforce Admin
Salesforce Case Assignment Rules
Salesforce Case Assignment Rules: Queues, Sort Order, Catch-All Rules, &Troubleshooting
Salesforce Admin
Salesforce Approval Process
Salesforce Approval Process: Classic Setup vs New Flow Approvals — Which Should You Use?
Salesforce Admin

Stay Updated with Salesforce Tutorials

Get the latest Salesforce guides, tutorials, and developer tips delivered to your inbox.
slaesforce corner mascot

Explore More Topics

  • salesforce admin
  • salesforce developer
  • Salesforce Admin
  • salesforce tutorial
  • salesforce automation
  • Salesforce Development
  • salesforce security
  • salesforce apex
  • Apex Development
  • lightning web components
  • Lightning Web Components
  • Salesforce Tutorials
  • salesforce lwc
  • salesforce best practices
  • Salesforce Tools
horizontal-dark-transparent

Learn Salesforce development with practical tutorials, Apex guides, integration examples, and real-world solutions for developers.

  • Quick Links:
  • About
  • Contact
  • Privacy Policy
  • Disclaimer
  • Terms & Conditions
Facebook Twitter Youtube Linkedin-in

Salesforce Corner © 2026

Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?