You need to sign in to do that
Don't have an account?
saleforce bee
Autosave record in lightning
I am trying to achieve Autosave of the record every 5 minutes in Lightning.
Here is the code for Common component which can be included any page that record has to be auto-saved without user intervention
Everything works as expected. Only issue is that I can't kill autosave recursion loop when I move to other lightning page. Is there a way to clear the autosave loop , I am using cleartimeout in the code.
autoSave : function(component,event)
{
var thisHelper=this;
var windowHelper=window;
var timeValue=component. get("v. timer");
component. set("v. timerValue", window. setTimeout(
$A. getCallback(function(){
// To avoid auto save method call if component becomes invalid
if(component. isValid()){
//Fire component event to access child component methods
var autoSaveEventValue = component. getEvent("autoSaveEvent");
autoSaveEventValue. fire();
thisHelper. autoSave(component);
}
// Clear the timer if component becomes invalid
else{
windowHelper. clearTimeout( component. get("v. timerValue") );
}
}
),timeValue));
},
Here is the code for Common component which can be included any page that record has to be auto-saved without user intervention
Everything works as expected. Only issue is that I can't kill autosave recursion loop when I move to other lightning page. Is there a way to clear the autosave loop , I am using cleartimeout in the code.
autoSave : function(component,event)
{
var thisHelper=this;
var windowHelper=window;
var timeValue=component. get("v. timer");
component. set("v. timerValue", window. setTimeout(
$A. getCallback(function(){
// To avoid auto save method call if component becomes invalid
if(component. isValid()){
//Fire component event to access child component methods
var autoSaveEventValue = component. getEvent("autoSaveEvent");
autoSaveEventValue. fire();
thisHelper. autoSave(component);
}
// Clear the timer if component becomes invalid
else{
windowHelper. clearTimeout( component. get("v. timerValue") );
}
}
),timeValue));
},
- You can take advantage of the built-in create and edit record pages in Salesforce1 to create or edit records via a Lightning component.
- The following component contains a button that calls a client-side controller to display the edit record page.
- https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_records_save.htm
- https://success.salesforce.com/ideaView?id=08730000000BqH1AAK
Let us know if it helps.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
http://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/ (http://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/" id="ext-gen103" rel="nofollow" target="_blank)
My functional code looks like this: