In my previous article, we have learned how SFDX is configured for building LWC and a very basic app HelloLWC, now time to explore more complex things. In this article, I am going to talk about how LWC works with salesforce data. Salesforce provides several ways for Lightning web components to work with data. Always start with the simplest solution and move to a solution that allows for more customization as needed.
Use Lightning Data Service (LDS) to Work with Data
Use Apex to Work with Data
1) Use Lightning Data Service (LDS) to Work with Data
Lightning Data Service is the preferred (and easiest) way to work with Salesforce data. With Lightning Data Service, developers use JavaScript to connect components to Salesforce data. There are multiple benefits while using LDS:
Lightning Data Service maximizes performance. When a record is cached, it’s retrieved from the cache, eliminating unnecessary calls to the server.
Lightning Data Service maintains consistent, up-to-date data across multiple components and clients throughout the app lifecycle. If several components use Lightning Data Service to work with a record, and one of them updates the record, the other components automatically reflect that update.
It respects CURD Access, FLS, and sharing setting
Support all custom and standard object
There are two ways to use LDS
Using Base Components-Below are 3 base Lightning components built on Lightning Data Service (LDS)
Lightning-record-view-form
lightning-record-edit-form
Using Wire adapters and functions in the lightning/ui*Api modules
2) Use Apex to Work with Data
So far we learned that LDS is the best approach however, there are some limitations as well. sometimes, neither the lightning-record-*-form components nor the LDS wire adapters and functions suit a particular use case. For example, when you want to customize a single-record data transaction or perform multi-record operations on a single transaction, Apex is the best choice. There are three ways to apex method.
No comments:
Post a Comment