CLOSE YOUR QUICK ACTION ONCE THE ACTION PERFORMED

Hola Trailblazer Community,

Today i am gonna share some solution for the problem that how to close the GLOBAL action once the record is created or once the once the action is performed.

Use Case : I have created the global action from visualforce page OR lightning component how i will close the action automatically if my action completed the task.

So .....Here we go...!!

I will start from example...

I have visualforce page. In my visualforce page i am creating contact. Now i want one global action for crating the contact and after creating the contact my global action should close and my current page should redirect to the contact which i have created from the action.


//APEX CONTROLLER

public with sharing class CloseAction {

    public String lastname{get;set;}
    public String contactId{get;set;}
    
    public TestCloseAction(){}
    
    public void submit(){
        // Create contact with all required field
        Contact ccon = new Contact();
        con.FirstName = firstname;
        con.LastName = lastname;
        insert con;
        
        if(con.id != null){
             contactId = con.id;
        }
       
    }
}


//VISUALFORCE PAGE

<apex:page controller="CloseAction">
    <apex:includeScript value="/canvas/sdk/js/publisher.js" />
    <apex:form >
    <apex:actionRegion >
    <apex:outputPanel id="tst">
        <script>
            function complete1() {
                var check1= '{!check}';
                //alert(check1);
                var conid = '{!ct.id}';
                alert(conid);
                sforce.one.navigateToSObject(conid);
                Sfdc.canvas.publisher.publish({ name : "publisher.close", payload : { refresh:"true" }});
                
             }
        </script>
        
        FirstName : <apex:inputText value="{!firstname}"/>
        LastName : <apex:inputText value="{!lastname}"/>
        <apex:commandButton value="Save" action="{!method1}" rerender="tst" oncomplete="complete1();"/>
        </apex:outputPanel>
        </apex:actionRegion>  
        </apex:form>

  
</apex:page>

                       
A       

Here it is for closing quick action i have added publisher.js file.

So what this code will do is. When you will click global action -> Action window will open ->
Enter First Name & Last Name -> Click Submit. When record is created the action will close
and page will be redirected on the record.


I have added VF page in global action.
The VF page will in the global action. After
clicking save action will close and page will
redirect to  the record page.
As in my apex code i am inserting the contact.


Note: This is the method to close the quick action when your action uses Visualforce Page. 
          If your component uses the lightning component then you have to use the
          $A.get("e.force:closeQuickAction").fire() in your controller. Hopefully i will share that also in detail.

Happy Coading...🖳😊...!!!!

Comments

Popular posts from this blog

PATH IS NOT COMING IN MOBILE??

WHATSAPP INTEGRATION WITH SALESFORCE

UPLOAD FILE FROM JAVASCRIPT REMOTING