Activity Forums Salesforce® Discussions What is Lightning Data Services in Salesforce?

  • shradha jain

    Member
    July 26, 2018 at 12:04 pm

    Lightning Data Service is used to load, create, edit, or delete a record in your component without requiring Apex code. It handles sharing rules and field-level security for you. In addition to not needing Apex, it improves performance and user interface consistency. Lightning Data Service identifies and eliminates requests that involve the same record data, sending a single shared data request that updates all relevant components. Not only does this eliminate inconsistent data between components, it also provides a way to cache data to work offline in case the user gets disconnected, intelligently syncing the data once the connection is restored. Data access with Lightning Data Service is simpler than the equivalent using a server-side Apex controller.

  • shariq

    Member
    September 18, 2018 at 12:24 am

    Hi,

    Use Lightning Data Service to load, create, edit, or delete a record in your component without requiring Apex code. Lightning Data Service handles sharing rules and field-level security for you. In addition to not needing Apex, Lightning Data Service improves performance and user interface consistency.
    At the simplest level, you can think of Lightning Data Service as the Lightning Components version of the Visualforce standard controller. While this statement is an over-simplification, it serves to illustrate a point. Whenever possible, use Lightning Data Service to read and modify Salesforce data in your components.

    Data access with Lightning Data Service is simpler than the equivalent using a server-side Apex controller. Read-only access can be entirely declarative in your component’s markup. For code that modifies data, your component’s JavaScript controller is roughly the same amount of code, and you eliminate the Apex entirely. All your data access code is consolidated into your component, which significantly reduces complexity.

    Lightning Data Service provides other benefits aside from the code. It’s built on highly efficient local storage that’s shared across all components that use it. Records loaded in Lightning Data Service are cached and shared across components. Components accessing the same record see significant performance improvements, because a record is loaded only once, no matter how many components are using it. Shared records also improve user interface consistency. When one component updates a record, the other components using it are notified, and in most cases, refresh automatically.
    Loading a Record
    Loading a record is the simplest operation in Lightning Data Service. You can accomplish it entirely in markup.
    Saving a Record
    To save a record using Lightning Data Service, call saveRecord on the force:recordData component, and pass in a callback function to be invoked after the save operation completes.
    Creating a Record
    To create a record using Lightning Data Service, declare force:recordData without assigning a recordId. Next, load a record template by calling the getNewRecord function on force:recordData. Finally, apply values to the new record, and save the record by calling the saveRecord function on force:recordData.
    Deleting a Record
    To delete a record using Lightning Data Service, call deleteRecord on the force:recordData component, and pass in a callback function to be invoked after the delete operation completes.
    Record Changes
    To perform tasks beyond rerendering the record when the record changes, handle the recordUpdated event. You can handle record loaded, updated, and deleted changes, applying different actions to each change type.
    Errors
    To act when an error occurs, handle the recordUpdated event and handle the case where the changeType is “ERROR”.
    Considerations
    Lightning Data Service is powerful and simple to use. However, it’s not a complete replacement for writing your own data access code. Here are some considerations to keep in mind when using it.
    Lightning Data Service Example
    Here’s a longer, more detailed example of using Lightning Data Service to create a Quick Contact action panel.
    SaveRecordResult
    Represents the result of a Lightning Data Service operation that makes a persistent change to record data.

    Hope this helps!

  • Parul

    Member
    September 19, 2018 at 4:34 am

    Hi

    Salesforce introduced Lightning Data Service in Winter 17 as a pilot program. Use Lightning Data Service to load, create, edit, or delete a record in your component without requiring Apex code. Lightning Data Service handles sharing rules and field-level security for you.

    It’s built on highly efficient local storage that’s shared across all components that use it. Records loaded in Lightning Data Service are cached and shared across components. Components accessing the same record see significant performance improvements, because a record is loaded only once, no matter how many components are using it. Shared records also improve user interface consistency. When one component updates a record, the other components using it are notified, and in most cases, refresh automatically.

    Advantages of Lightning Data Service

    No need to write any Apex class
    No need to write SOQL
    Field level security and record sharing is inbuilt
    CRUD operation supported
    Shared cache is used by all standard and custom components
    Auto notification to all components
    Supports offline in Salesforce 1

    THanks.

  • Prachi

    Member
    September 21, 2018 at 5:30 am

    hi,

    Use Lightning Data Service to load, create, edit, or delete a record in your component without requiring Apex code.At the simplest level, you can think of Lightning Data Service as the Lightning Components version of the Visualforce standard controller.It’s built on highly efficient local storage that’s shared across all components that use it. Records loaded in Lightning Data Service are cached and shared across components. Components accessing the same record see significant performance improvements, because a record is loaded only once, no matter how many components are using it.

    thanks.

  • William

    Member
    January 15, 2019 at 7:10 am

    Lightning Data Services (LDS) is a new mechanism in Salesforce that was proposed in winter 2017 to edit, delete, or update records in Lightning Components. LDS reduces the need for APEX methods and improves the overall performance and user-interface consistency. With the help of simple mark-ups, records and the related fields can be quickly loaded to the Lightning Component. In this way, LDS could be taken as a strong consideration before you start with next component development. This can be definitely be taken as the big deal for the future projects.

Log In to reply.

Popular Salesforce Blogs