{{appName}} (LDS)
- Data-Layer for Lightning (similar to Visualforce standard controller)
- Developers no longer have to write your own controller code
- All the data access code is contained within the LDS component
force:recordData
- Significantly reducing the complexity of Lightning apps and pages
Combine Multiple data-requests on same record to single data-request
LDS Goals
- Minimize XMLHttpRequests (XHRs)
- Fetch records once, reducing network transfers, app server load, and database server load
- Cache record data on the client, separate from component metadata
- Share record data across components
- Enable progressive record loading, caching, and merging more fields and layouts into the cache
- Enable proactive cache population
- Promote consistency by using only one instance of the record data across multiple components
- Create notifications when record data changes
How to use LDS? - force:recordData
- input attributes:
- recordId: Id of the sObject Record to load
- mode: determines the behavior of notifications and
what operations are available to perform with the record:
- layoutType: to adapt to layout definitions:
- fields: which fields in the record to query. example: "Name,BillingCity,BillingState"
- output attributes:
- targetRecord: the attribute that will be populated with the loaded record
- targetFields: populated with the simplified view of the loaded record
- targetError: populated with any errors
Example
({
handleRecordUpdated: function(component, event, helper) {
var eventParams = event.getParams();
if(eventParams.changeType === "LOADED") {
// record is loaded (render other component which needs record data value)
console.log("Record is loaded successfully.");
} else if(eventParams.changeType === "CHANGED") {
// record is changed
} else if(eventParams.changeType === "REMOVED") {
// record is deleted
} else if(eventParams.changeType === "ERROR") {
// there’s an error while loading, saving, or deleting the record
}
}
})