Skip to main content

Hi everyone, 

We are currently working on developing an offline-capable Lightning Web Component (LWC) that displays related records of Object A on the detail page of Object B. The goal is to ensure that users can view and interact with these related records even when they are not connected to the internet.

Approach 1: Using GraphQL

Initially, I explored using GraphQL to fetch the related records. However, I encountered performance issues when the number of records exceeded 10. The response times became noticeably slower, which is not ideal for an offline experience.

Approach 2: Implementing Cacheable Apex

To address the performance concerns, I transitioned to using a cacheable Apex method. This approach improved performance by leveraging client-side caching, allowing for faster data retrieval. However, I faced a new challenge when attempting to update records using the updateRecords function from Lightning Data Service (LDS).

Issue with updateRecords in Offline Mode

When operating in offline mode, I observed that only 1 or 2 related records were being updated, despite the intention to update all 4 related records. This inconsistency in behavior suggests that the updateRecords function may not be fully compatible with offline scenarios, possibly due to limitations in how LDS handles data synchronization when offline.

Request for Guidance

I am seeking advice on how to effectively implement offline support for updating related records in LWC. Specifically, I would appreciate insights into:

  • Best practices for using LDS's updateRecords function in offline scenarios.
  • Alternative approaches for updating related records offline, such as utilizing the Mobile SDK's entity framework for offline data management.
  • Recommendations for ensuring data consistency and synchronization when transitioning between online and offline states.

Any guidance or resources you can provide would be greatly appreciated. 

Please let me know if codebase files are needed here.   

 

@Irfan Syed, @Adam Liechty, @Amber Craig, @Ashwin Nair, @Saket Agarwal

5 respostas
  1. 19 de mai. de 2025, 06:09

    @Olajide Otolorin -Prince There is a Question object which is related to Object A. Now, I want to show the Question object records on the view of Object A, in edit mode, so that the user's responses can be saved.

    Currently, I’m using updateRecords from LDS to save the data, but it's behaving weirdly — sometimes it saves 1 record in the draft, sometimes 2 or 3 — even though I’m trying to update 5-6 records at once. The same code works fine online. Is there any workaround for this?

    I’m fetching Question object data using a cacheable Apex method via a wire call in the LWC that is placed on the Object A

    record page. 

    Below is the code snippet of updateRecord lds  

    const savePromises = updates.map(recordInput =>

              updateRecord(recordInput).catch(error => {

                  console.error(`Failed to update ${recordInput.fields.Id}:`, error);

              })

          );

      

          Promise.all(savePromises)

              .then(() => {

                  this.showToast('Success', 'All inspection answers saved.', 'success');

              })

              .catch(error => {

                  console.error('Save failed:', error);

                  this.showToast('Error', 'Some records failed to save.', 'error');

              });

0/9000