ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Reusable Lightning Notification On Record Update (Backend/API/UI) using Lightning Data service

Home / Article & Blogs / Salesforce / Lightning / Reusable Lightning Notification On Record Update (Backend/API/UI) using Lightning Data service
By Abhishek Raj inLightning, Salesforce

A very common scenario faced in various organizations is that multiple users are working on same set of records and end up editing the same record which has been edited by a different user. The user who last clicks on the save button gets error message saying “error…being edited by…”. All last typed text is lost.  The possibility of our edits colliding in the same record is a real risk. So, it is only a matter of time before one of us has to retype an entry because one of us entered, edited, and saved before the other was finished with an edit. This is especially necessary for those of us that use Salesforce as a full-fledged service desk.

Salesforce does not prevent multiple users from editing a record / custom object at the same time so when they try to save their edits, they receive an error and have to start all over.One of the workaround to this scenario is to use Lightning Data Service(LDS).

What is Lightning Data Services?

We use Lightning Data Service to load, create, edit, or delete a record in your component without using Apex code. In addition to not needing Apex, Lightning Data Service improves performance and user interface consistency. LDS is the Lightning Components counterpart to the Visualforce standard controller, providing access to the data displayed on a page. Without LDS, each component within an app makes independent calls to the server to perform CRUD(create,read,update,delete) operations on a record, even if all components in the app pull from the same record data. Each server call reduces performance, leaving users twiddling their thumbs instead of working with their data. These independent server calls can also lead to inconsistencies, creating situations where a server call refreshes one component, leaving other components out of date.

Hypothetical situation time!

So, you are editing records of any object which has many fields to be filled. While you are editing, fields of that object get updated by integration from the back-end. In this case you might end up filling all the fields and clicking on save button which would result in  loss of your valuable data and time. This could be really frustrating if the number of fields to be updated is more. We can escape from this situation by using LDS. When saving a record through LDS, the local cache isn’t updated until the save is complete. When the save is successfully completed on the server, the cache is updated to the latest version of the record from the server, and all components with a reference to that record are notified. You don’t have to worry about manually reloading the record into the cache after saving and making repeated server calls to check the update status. LDS handles all the work for you. When the record gets updated by some user, the other users working on the same record gets a “Toast Message Notification” notifying about the record updation without refreshing the record page thus no critical data loss occurs.

Bpic1.png

Manually editing the record. At the same instant the record gets updated from the backend.

Screenshot (27).png

When the record is updated from the backend, the user who is editing same record gets toast message notification that the record is updated.

Screenshot (31).png

We can see in the above image that the Account name and Phone number has been updated while the user is still updating the record. So, now the user can stop making any further changes and save any critical data, thus saving his time and effort.

We just need to add the component given below on the layout and it will work on any object. 

reusableComp.cmp

[sourcecode language=”java”]
<aura:component implements=”force:appHostable, flexipage:availableForAllPageTypes, flexipage:availableForRecordHome, force:hasRecordId, forceCommunity:availableForAllPageTypes, force:lightningQuickAction” access=”global” >
<aura:attribute name=”dataRecord” type=”Object” default=”{‘Name’:”,’Phone’:”}”/>
<aura:attribute name=”recordSaveError” type=”String” default=””/>
<aura:handler name=”init” value=”{!this}” action=”{!c.doInit}”/>
<force:recordData aura:id=”recordLoader” recordId=”{!v.recordId}” layoutType=”FULL” targetFields=”{!v.dataRecord}” targetError=”{!v.recordSaveError}” recordUpdated=”{!c.handleRecordUpdated}” />
<aura:if isTrue=”{!not(empty(v.recordSaveError))}”>
<div class=”recordError”>
{!v.recordSaveError}</div>
</aura:if>
</aura:component>
[/sourcecode]

reusableCompController.js

[sourcecode language=”java”]
({
doInit: function(component,event,helper){
component.find(“recordLoader”).reloadRecord(true);
//set time-out
helper.setTimer(component);
},

handleRecordUpdated: function(component, event, helper) {
var eventParams = event.getParams();
if(eventParams.changeType === “CHANGED”)
{
component.find(“recordLoader”).reloadRecord();
// get the fields that are changed for this record
var changedFields = eventParams.changedFields;
// record is changed so refresh the component (or other component logic)
var resultsToast = $A.get(“e.force:showToast”);
resultsToast.setParams({
“mode”: “sticky”,
“title”: “Saved”,
“message”: “The record was updated.”
});
resultsToast.fire();

} else if(eventParams.changeType === “LOADED”) {
// record is loaded in the cache
} else if(eventParams.changeType === “REMOVED”) {
// record is deleted and removed from the cache
} else if(eventParams.changeType === “ERROR”) {
}
},
})
[/sourcecode]
reusableCompHelper.js

[sourcecode language=”java”]
({
setTimer: function(component){
var that = this;
window.setTimeout(
$A.getCallback(function() {
component.find(“recordLoader”).reloadRecord();
that.setTimer(component);
}),1000 //time after which the component reloads to check for any change in the record data
);
}
})
[/sourcecode]

Considerations

  • CRUD operations can be performed only on one record at a time. Bulk record operations are not supported.
  • Lightning Data Service is only available in Lightning Experience and Salesforce1.
  • Lightning Data Service doesn’t currently support every entity type. Here’s the list of supported entity type Lightning Data Service: Considerations .
Lightning componentLightning data serviceNotification on Record Edit using Lightning Data ServiceUpdate Record using Lightning Data Service
81
Like this post
10 Posts
Abhishek Raj

Search Posts

Archives

Categories

Recent posts

Meet OmniStudio – Revolutionize Your Creative Work

Meet OmniStudio – Revolutionize Your Creative Work

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

  • Previous PostGeneric Lightning Component for Follow/UnFollow Record
  • Next PostLightning Data Service

Related Posts

Meet OmniStudio – Revolutionize Your Creative Work
Salesforce

Meet OmniStudio – Revolutionize Your Creative Work

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

1 Comment

  1. sfdcbrahma
    Reply
    3 February 2018

    That’s nice.

    Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT