0

I’ve been building a LWC that uses lightning-datatable to display records of the Task sObject. Since the Task object is not supported by the lightning UI API, my understanding (and tested) is that I can’t @wire my Apex method that queries the Tasks. This is a well established annoyance: https://ideas.salesforce.com/s/idea/a0B8W00000GdXHsUAN/support-task-and-event-objects-in-ui-api-with-lwc

And since I can’t use UI API and the wire service, I can’t use refreshApex()/getRecordNotifyChange() to update the lightning-datatable after an inline update operation.

The best I can come up with so far is to refresh the entire page using something like window.location.reload();. But that is not ideal.

I would settle for something that would cause the LWC alone to rerender (not the entire page), but I can't seem to find any code that would accomplish that.

In sum, how might we refresh Task data displayed in lightning-datatable after an inline edit operation?

2
  • Just to clarify, is the inline edit operation from within your datatable or off the record itself? Commented Dec 22, 2022 at 20:47
  • Hi, yes the inline edit is within the datatable itself. The standard inline edit functionality of the lightning-datatable component. Commented Dec 23, 2022 at 18:22

1 Answer 1

0

I ended up creating a Platform Event (fired when a Task is created/updated) that the LWC can subscribe to. Then in response to that event, the LWC calls the Apex method again to get fresh records. I was still having trouble getting the datatable to update when the @track property corresponding to the data is updated by that second Apex invocation. However, reassigning the tracked property with the spread operator fixed that problem:

handleDataUpdatedEvent() { console.log("*******calling handleDataUpdatedEvent"); // Get the updated records getRecords({strObjectApiName: this.relatedObjectApiName, strFieldPaths: this.fieldString, strWhereClause: this.whereClause, recordId: this.recordId, strRelationshipFieldAPIName: this.relationshipFieldApiName}) .then(data=>{ console.log('********data from get Updated Records: ' + JSON.stringify(data)); this.records = [...data]; this.sortData(this.sortBy, this.sortDirection); console.log("********this.records: " + JSON.stringify(this.records)); }) .catch(error=>{ this.error = error; }); } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.