We have a simple custom javascript button that when clicked assigns the current lead to the current user.
I'm trying to replicate this in lightning in the most similar way I can, but haven't found a great method so far.
I found this article for launching a custom lightning component from a quick action. I modified it to work for lead record and it works as expected, but the interface displays a popup window - does the actual update I want and never goes away.
I feel like I'm close, but extremely new to lightning components so I'm hoping someone can help me get the desired result which is just clicking a button and the owner changing (a notification saying successfully changed or something would be fine).
Here is my lightning component code:
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:refreshView').fire();
}
})
Apex class:
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;
}
}
And, lastly, my quick action
If there is a better way to do this, I'm all for it. The goal is to change an owner without any extra clicks. Eventually it will be to assign to specific queue without any extra clicks. Thanks in advance.