We have a lightning component thats being used a quick action. When the lightning component is activated it calls the init handler multiple times
Component
<aura:component implements="force:lightningQuickAction,force:hasRecordId,flexipage:availableForAllPageTypes" controller="CloneObject">
<aura:attribute name="recordId" type="String"/>
<aura:attribute name="name" type="String"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<ui:inputText label="Quote Name" value="{!v.name}"/>
<br/>
<ui:button class="slds-button slds-button--neutral" press="{!c.clone}" label="Clone" />
</aura:component>
js controller
({
doInit : function(component, event, helper) {
var action = component.get("c.doInit");
var recordId = component.get("v.recordId");
console.log(recordId);
action.setParams({
"recordId" : recordId
});
action.setCallback(this, function(response) {
var state = response.getState();
if(component.isValid() && state == "SUCCESS"){
component.set("v.name", response.getReturnValue());
} else {
console.log('There was a problem and the state is: '+state);
}
});
$A.enqueueAction(action);
},
clone : function(component, event, helper) {
var action = component.get("c.cloneQuote");
var recordId = component.get("v.recordId");
console.log('record Id');
console.log(recordId);
action.setParams({
"objectId": recordId,
"cloneAttachments": true
});
action.setCallback(this, function(response) {
var state = response.getState();
if(component.isValid() && state == "SUCCESS"){
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/" + response.getReturnValue()
});
urlEvent.fire();
} else {
console.log('There was a problem and the state is: '+state);
}
});
$A.enqueueAction(action);
}
})
Apex Controller
public class CloneObject {
@auraEnabled
public static String doInit(String recordId) {
return [SELECT Name FROM Quote WHERE Id = :recordId].Name;
}
}
Output when the quickaction is clicked