It seems to be doing the record update based on apex code, but it launches a quickaction screen with a cancel button that doens't go away. I've seen it posted that you can use
$A.get("e.force:closeQuickAction").fire();
It is not working for me. I'm not sure if I'm not puting that code in the right place but I'm hoping someone can help me figure out a way to click the quick action button, have the lead change ownership, and that's it.
Here is my code so far:Component:
<aura:component implements="force:lightningQuickAction,force:hasRecordId" controller="LightningComponent_MoveToMarketing" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>
Controller:
({
doInit : function(component, event, helper) {
var leadId = component.get("v.recordId");
var action = component.get("c.changeOwnerMethod");
action.setParams({
leadId : leadId
});
action.setCallback(this, function(response) {
if(response.getState() === "SUCCESS") {
console.log("Lead Owner Changed To Current login User");
var rec = response.getReturnValue();
console.log(rec.OwnerId);
}
});
$A.enqueueAction(action);
$A.get("e.force:closeQuickAction").fire();
$A.get('e.force:refreshView').fire();
}
})
Apex Class:
Any ideas?public class LightningComponent_MoveToMarketing {
@AuraEnabled
public static Lead changeOwnerMethod(Id leadId) {
if(leadId != null) {
Lead l = [SELECT OwnerId FROM Lead WHERE Id = :leadId];
l.OwnerId = UserInfo.getUserId();
//update case Ownerid with loggedin userid.
update l;
return l;
}
return null;
}
}
Move
inside the callback function. It should be good then.$A.get("e.force:closeQuickAction").fire();
$A.get('e.force:refreshView').fire();
Your controller should be like this.
Please mark it solved if this is working for you.Thanks.({
doInit : function(component, event, helper) {
var leadId = component.get("v.recordId");
var action = component.get("c.changeOwnerMethod");
action.setParams({
leadId : leadId
});
action.setCallback(this, function(response) {
if(response.getState() === "SUCCESS") {
console.log("Lead Owner Changed To Current login User");
var rec = response.getReturnValue();
console.log('->'+rec.OwnerId);
$A.get("e.force:closeQuickAction").fire();
$A.get('e.force:refreshView').fire();
}
});
$A.enqueueAction(action);
}
})