function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James Kacerguis 5James Kacerguis 5 

Cannot get quickaction to close after clicking lightning component quick action

Hello All,
I'm extremely new to lightning components and trying to replace some of our custom javascript buttons with lightning compatible options.  One button takes ownership of a lead.  I found a post that does something similar for cases and tried to modify it for my purpose: https://learnownlightning.blogspot.com/2018/01/change-owner-update-record-using.html

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:
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;
    }

}

Any ideas?
 
Best Answer chosen by James Kacerguis 5
lnallurilnalluri
Move 
$A.get("e.force:closeQuickAction").fire();
        $A.get('e.force:refreshView').fire();

inside the callback function. It should be good then.

Your controller should be like this.
({
 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);

 }
})

Please mark it solved if this is working for you.

Thanks.​​​​​​​

All Answers

lnallurilnalluri
Move 
$A.get("e.force:closeQuickAction").fire();
        $A.get('e.force:refreshView').fire();

inside the callback function. It should be good then.

Your controller should be like this.
({
 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);

 }
})

Please mark it solved if this is working for you.

Thanks.​​​​​​​
This was selected as the best answer
James Kacerguis 5James Kacerguis 5
Awesome, that worked!  Could you clarify exactly which statement is running that apex code?  E.G. is it the $A.enqueueAction(action);?  If so, what is the $A?

What I'm thinking would be more useful than just closing the quick action window would be displaying a notificaiton that the lead was was reassigned and then closing.  Is there a way to set a timeout value of a few seconds and then closing?  Would that be done in the setCallback function area?

Thanks again!
lnallurilnalluri
@James. You are welcome.

Yes $A.enqueueAction(action) is running apex.

$A.enqueueAction(action) sends the request to server. More precisely, it adds the call to the queue of asynchronous server calls. That queue is an optimization feature of Lightning.

Also, to display the notification check and try replacing your controller code with below snippet.
 
 
({
    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);
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Success!",
                    "message": "The record has been assigned successfully.",
                    "type" : "success"
                });
                
                toastEvent.fire();
                setTimeout(function(){ 
                    $A.get("e.force:closeQuickAction").fire();
                $A.get('e.force:refreshView').fire();
                },3000);
            }
        });
        $A.enqueueAction(action);
        
    }
})

 
James Kacerguis 5James Kacerguis 5
Perfect, thank you.  Just to double check, there is no way to have the quick action not display at all and ONLY display the toast message, is there?
lnallurilnalluri
@james. I think it's not possible for a quick action. 
James Kacerguis 5James Kacerguis 5
Okay, do you have any better suggestion for making something like this happen with a button click in lightning?  E.G. a user driven action that triggers some apex and doesn't need any other user input?  
lnallurilnalluri
@James, If you dont want it as quick action.. make the following changes to your component.
 
<aura:component implements="force:lightningQuickAction,force:hasRecordId,flexipage:availableForAllPageTypes" controller="LightningComponent_MoveToMarketing" access="global" >
    <aura:attribute name="buttonName" type="String" default="Assign"/>
    <div align="center">
    <h1 style="font-weight:bold">Owner Assignment</h1>
    </div>
    <lightning:button label="{!v.buttonName}" aura:id="assignmentButton" onclick="{!c.doInit}"/>    
</aura:component>

controller.js
 
({
    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);
                component.set("v.buttonName","Assigned");
                component.find("assignmentButton").set("v.disabled",true);
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Success!",
                    "message": "The record has been assigned successfully.",
                    "type" : "success"
                });
                
                toastEvent.fire();
                setTimeout(function(){ 
                    $A.get("e.force:closeQuickAction").fire();
                $A.get('e.force:refreshView').fire();
                },3000);
            }
        });
        $A.enqueueAction(action);
        
    }
})

then go back to your lead page and edit it, search for your component name in the component list on the left side drag it and drop into the flexi page whereever you want.

User-added image


It should look something like

User-added image


Here by implementing the interface flexipage:availableForAllPageTypes in your component, it is available to drop it on flexipage.


Let me know if you have any other questions.


Thanks.




​​
lnallurilnalluri
@James Also, in this case you may not need $A.get("e.force:closeQuickAction").fire(); and timeout.
James Kacerguis 5James Kacerguis 5
Yes, this is great and I removed the closeQuickAction and timeout and it will works as expected.  One more question though, is there a way to get the button to display on a similar background to other components?  Currently is blank / transparent.  It would be great if it just looked like the dupolicate lead component :

User-added image
 
lnallurilnalluri
@James, yup by wrapping it into a card we can
 
<aura:component implements="force:lightningQuickAction,force:hasRecordId,flexipage:availableForAllPageTypes" controller="LightningComponent_MoveToMarketing" access="global" >
    <aura:attribute name="buttonName" type="String" default="Assign"/>
    
    
    <lightning:card>
        <aura:set attribute="title">
            <lightning:icon iconName="action:change_owner" size="xx-small"/>&nbsp;
            <strong>Owner Assignment</strong>
        </aura:set>
        <div align="center">
            <lightning:button variant="brand" label="{!v.buttonName}" aura:id="assignmentButton" onclick="{!c.doInit}"/>
        </div>
    </lightning:card>
</aura:component>

User-added image
James Kacerguis 5James Kacerguis 5
Awesome, exactly what I needed.  Thank you for all your help!
Sam JordanSam Jordan
Thanks Every One for Sharing this valuable info 

Regards : YRKKH Upcoming Story (https://serialstalk.com/yeh-rishta-kya-kehlata-hai-upcoming-story/ )
python trainingpython training
Thanks for your excellent blog and giving great kind of information. So useful. Nice work keep it up thanks for sharing the knowledge. 3RI Technologies (https://www.3ritechnologies.com/course/python-programming-training-in-pune/)

 
Rahil ShanRahil Shan
Thanks for sharing this 
please check out this katmoviehd (https://moviesnotes.com/katmoviehd), 7starhd (http://moviesnotes.com/7starhd/), 9xmovies (http://moviesnotes.com/9xmovies), moviesflix (http://moviesnotes.com/moviesflix/), downloadhub (http://moviesnotes.com/downloadhub)
anuragh sharmaanuragh sharma
Thanks for sharing these awesome extensive information here. Relly very nice and important....
Download and Watch Hollywood South Hindi Dubbed
Hiren Patel 45Hiren Patel 45
Thank you lnalluri,
I have applied the code and it runs properly.
Grade Calculator (https://www.gradecalculator.tech/) and Password Generator (https://www.password-generator.tech) and Convert Decimal to Fraction (https://www.decimal-to-fraction.com/)
abhishek kumar 694abhishek kumar 694
Yes, this is great and I removed the closeQuickAction and timeout and it will works as expected. tamilrockers (https://tricksnhub.com/tamilrockers/)
Thanks Every One for Sharing this valuable info. Regards Movierulz (https://tricksnhub.com/movierulz/)
shaiva sharmashaiva sharma
Yes, this is great and I removed the closeQuickAction and timeout and it will works as expected. khabar bollywood (https://www.khabarsbollywood.com/)
 
Roger KartRoger Kart
I hope the answer provided above solved your problem. You can check this song and relax for a while. Duniya Se Tujhko Churake Dj Song Mp3 Download. (https://anylyricsguru.com/duniya-se-tujhko-churake-dj-song/)
Akash kumar 160Akash kumar 160
hey i was also Seaching for this question and here i found almost all answer of my question regarding this. TechDeskIndia (https://www.techdeskindia.com/)
Also want to know how these sites Movierulz ms (https://www.techdeskindia.com/2020/02/movierulz-movies.html) sells their movies illegalyy??
Ladle BhaiLadle Bhai
shubham prashar 7shubham prashar 7
tool for download thumbnail (https://youtubethumbnaildownload.online)
tool for vimeo thumbnail downloader (https://youtubethumbnaildownload.online/vimeo.html)
tool for dailymotion thumbnail downloader (https://youtubethumbnaildownload.online/dailymotion.php)
Pagla WorldPagla World
You can watcyh full paka paak video here xxnx (https://www.xxnx.to/)
Aarti Jain 1Aarti Jain 1
Amazing article sir. A great information given by you in this blog. It really informative and very helpful. Keep posting will be waiting for your next blog.I was meaning to write something in my website & I got the idea ,Thank you!!
Python training (https://www.technobridge.in/python-training-course.php)in Pune
 
Akash Deb NathAkash Deb Nath
I want to thaks it's help me out to study best regards bhumi jankari (https://emarenas.com/information/bhumi-jankari/)
Web MusicWeb Music

Very nice to see. But i would like to mention this site https://www.google.nl/url?sa=t&url=https://webmusic.to/ (https://www.google.nl/url?sa=t&url=https://webmusic.to/) or you can visit: Webmusic (https://webmusic.to
Sidhartha pradhanSidhartha pradhan
Thank you so much for providing us.  visit https://currentaffairspro.com website to get daily Odia Song, Hindi Mp3, Panjabi Mp3 Song, Odia mp3 download, Hindi mp3 download & Dj song related content.
Odiashayari proOdiashayari pro
Thank you so much for providing us.  visit our website odiashayaripro.com to get daily cricket news, t20 world cup 2021, Asia cup 2021, and latest cricket news.
thewire blogthewire blog
Thank you for the information. Here is the Bigg Boss Tamil season 4 contestants (https://www.thewireblog.net/bigg-boss-tamil-contestants/)
memes opmemes op
Memesop (https://memesop.com) website provides daily New Odia Song, Whatsapp Video Status, Sambalpuri Song. Odia Dj Song Related Contents.
kuldeep tiwari 22kuldeep tiwari 22
Thanks for sharing also read Python Classes in Pune (https://www.sevenmentor.com/best-python-classes-in-pune.php)
Ojaswwee SharmaOjaswwee Sharma
Thank you for nice information 
sikhlens film festival
Danish MalikDanish Malik
Thanks for the information.
I am a developer at these two sites; visit mybag.pk and naturebounty.pk
Rohit RadhakrishnanRohit Radhakrishnan
Guys, please use headless LWC Quick actions.
More details here 
https://salesforcerealm.com/2021/12/13/headless-lwc-actions/
jimmy john 2jimmy john 2
You can download youtube thumbnails (https://youtubethumbnaildownload.net) from this website. https://youtubethumbnaildownload.net
Rohit Sharma 426Rohit Sharma 426
MkvCinemas (https://rohitsharma.co/mkvcinemas/) is your free movie's website to watch series and films. We offer you quick access, without registration, to more than 50,000 movies and 10,000 TV ...
Ajay PrajapatAjay Prajapat
 You are awesome for sharing all that knowledge on BA 3rd Year Result (https://www.examalert.co.in/ba-3rd-year-result/). I really appreciate revisiting your website. Thank you for your generosity! BSc 3rd Year Result (https://www.examalert.co.in/bsc-3rd-year-result/)
Ankita JadhavAnkita Jadhav
Thank you so much for everyonse contribution appreciated your supports. If you want to master any software langusge please visit our site. Web Development Classes in Pune (https://www.codeship.co.in/web-development-course-training-in-pune.php).
Ankita JadhavAnkita Jadhav
Thanks for the answers. Learn web designing (https://www.codeship.co.in/web-design-course-training-classes-pune.php) from one of the best software training institute in Pune.