Your chart refresh issue requires addressing all three focus areas: Lightning Data Service wire adapters for record data, getRecordNotifyChange usage for LDS cache invalidation, and real-time chart updates for the Chart.js visualization. Here’s the comprehensive solution:
Lightning Data Service Wire Adapters:
You’re using two separate wire adapters: getRecord for the forecast record and a custom Apex wire for opportunity data. These have different refresh mechanisms. The getRecord wire adapter automatically refreshes when LDS detects record changes made through Lightning Data Service (updateRecord, createRecord). However, your custom @wire(getOpportunities) doesn’t participate in LDS cache, so it never auto-refreshes.
Modify your component to store the wired Apex result properly:
wiredOpportunitiesResult;
@wire(getOpportunities, { forecastId: '$recordId' })
wiredOpportunities(result) {
this.wiredOpportunitiesResult = result;
if (result.data) {
this.processChartData(result.data);
}
}
Storing the result object (not just data) enables refreshApex to work.
getRecordNotifyChange Usage:
getRecordNotifyChange only invalidates LDS-managed records, not custom Apex query results. Use it after updating the forecast record itself to refresh the getRecord wire, but for the opportunity data, import and use refreshApex:
import { refreshApex } from '@salesforce/apex';
import { getRecordNotifyChange } from 'lightning/uiRecordApi';
async handleForecastUpdate() {
// After update logic
getRecordNotifyChange([{recordId: this.recordId}]);
await refreshApex(this.wiredOpportunitiesResult);
}
Call refreshApex with the stored result object, not the data property. This re-executes your getOpportunities Apex method and fetches fresh data.
Real-Time Chart Updates:
Chart.js requires explicit update() calls when data changes. Create a reactive pattern that updates the chart whenever wire data changes:
processChartData(data) {
this.chartData = this.transformToChartFormat(data);
if (this.chartInstance) {
this.chartInstance.data = this.chartData;
this.chartInstance.update('none');
}
}
The ‘none’ animation parameter makes updates instant, crucial for live forecast calls. Initialize this.chartInstance in renderedCallback when the canvas element is ready.
For your 30+ managers scenario where multiple users view the same forecast simultaneously, implement Change Data Capture to broadcast updates:
- Enable CDC on Opportunity object (Setup > Change Data Capture > Select Opportunity)
- Subscribe to CDC events in your LWC using empApi
- When a CDC event arrives, call refreshApex to update the chart
This ensures when one manager updates opportunities, all other managers’ charts refresh automatically without manual browser refresh. The combination of refreshApex for local updates and CDC for broadcast updates provides complete real-time synchronization across all forecast call participants.
Deploy these changes and your chart will refresh immediately when forecast or opportunity data changes, whether updated by the current user or colleagues in the same forecast review session.
This draft is based on general Salesforce knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.