function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

lightning data service vs APEX?

I'm trying to understand the efficiencies of Lightning Data Service versus using APEX. I DO understand that many people have a phobia regarding APEX, but I don't, so that's not a benefit to me. I'm really asking about things like performance (responsiveness), demands on the server, governor limits, etc.

Here's a specific example:
I'm building a Lightning Component (list.cmp) that iterates through 20 message__c records, using a tile.cmp to display 5 fields from message__c on each of the record tiles in the scrollable list. I can accomplish this 2 ways.
  1. listController calls APEX, returning a list<message__c>  of the 20 records with 5 fields per record. I aura:iterate through the list, passing a message__c object as the parameter. The tile.cmp receives the full message__c object and builds the tile. Or...
  2. listController calls APEX, returning a list of message__c Id numbers. I aura:iterate through the list passing only the recordId to tile.cmp, which uses force:recordData to pull the record data using LDS, then builds the tile.
Either way, I have to do a SOQL query, but in the second instance, I'm just pulling recordIds. I do understand that if those same message__c records are displayed in other components on the page, that changes in one place will be automatically reflected elsewhere, but for this example, that's not the case. Just viewing the data in this one place. So this is strictly a question about performace.

I have actually already built this using the first method and it works fine, but I'm really trying to drink the LDS Kool-Aid and use it wherever it makes sense. I just need more info to understand whether it makes sense.

Same question for saving a new record via LDS vs APEX. Is LDS faster? easier on the server? better with regard to governor limits?