0

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.

enter image description here

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

enter image description here

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.

0

You just need to fire off an event to close the dialog:

$A.get("e.force:closeQuickAction").fire();

This will close the window automatically. You'll still see the popup for a brief moment, but this is the best that we can really do at the moment.

|improve this answer|||||
  • Okay, I made the change as follows but it's still not working - it just shows the change owner window and doesn't close. $A.enqueueAction(action); $A.get('e.force:refreshView').fire(); $A.get("e.force:closeQuickAction").fire(); – jameskbw Oct 8 '19 at 19:35
  • Also, is there a way I could display some sort of success message in that window and just have the user click Ok button? – jameskbw Oct 8 '19 at 19:48
  • @jameskbw Yes, you could show a message and have them manually close it. – sfdcfox Oct 8 '19 at 20:05
  • Okay, I'll look into that more, but any idea why the quickaction is not closing with : $A.enqueueAction(action); $A.get('e.force:refreshView').fire(); $A.get('e.force:closeQuickAction').fire(); Do these need to be in a certain order? – jameskbw Oct 8 '19 at 20:18
  • @jameskbw You should probably put that logic in the success handler, not before. Other than that, it should work. Do you see any errors on the Developer Console (F12)? – sfdcfox Oct 8 '19 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.