0

For a client requirement in opportunity I have added a button to go to a visual force page. Before showing the next page though client wants to show a popup on that button click to confirm the operation. If not confirmed it should go to a different page. I am very new to salesforce. Please help.

Hasan Zubairi
  • 1,037
  • 4
  • 23
  • 57

1 Answers1

0

In case you are using the Lightning version of Salesforce, you can follow the following steps:

  • Create an Aura Component as follows:

.cmp file

<aura:component implements="force:lightningQuickActionWithoutHeader">
  Are you sure you want to proceed?
  <div class="slds-align_absolute-center">
    <lightning:button
      label="No"
      variant="destructive"
      onclick="{!handleNo}"
    ></lightning:button>
    <lightning:button label="Yes" onclick="{!c.handleYes}"></lightning:button>
  </div>
</aura:component>

controller.js (replace MyOtherVisualforce and MyVisualforce with your Visualforce names)

({
  handleNo: function (component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      url: "/apex/MyOtherVisualforce",
      isredirect: "true"
    });
    urlEvent.fire();
  },

  handleYes: function (component, event, helper) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      url: "/apex/MyVisualforce",
      isredirect: "true"
    });
    urlEvent.fire();
  }
});
  • Create a new Action for the Opportunity object (go to the Buttons, Links and Actions section of the Opportunity setup and create new Action) and as Action Type select Lightning Component and as Lightning Component select the one that you just created
  • Add the Action to your Opportunity layout

By doing this, the action will open your Aura Component which will present the two options that you need. After clicking one of the options, the e.force:navigateToURL will perform the redirection.

  • Thanks Oscar. I have created the said component but it is not showing in Lightning Component drop down. How to add the lightning component to the Action Type. – Hasan Zubairi Oct 23 '21 at 17:30
  • Error: No Lightning Component Quick Actions are available for your organization – Hasan Zubairi Oct 23 '21 at 17:55
  • Hi Hasan. Have you included the implements="force:lightningQuickActionWithoutHeader" in the first aura:component tag? It is really important for the Component to show in that picklist. If it is still not showing, the component is probably not deployed or saved in the org. Check your Developer Console to make sure that the component is there. – Óscar Gómez Balaguer Oct 23 '21 at 18:10
  • Thank you Oscar it worked. But I want to add this action to a button Like New Task. How can I add this action to a new task button? – Hasan Zubairi Oct 23 '21 at 20:35
  • What do you mean by a button like New Task? Do you mean as a Global Action? Could you update your answer with some screenshots with the desired behaviour? – Óscar Gómez Balaguer Oct 24 '21 at 17:30
  • I got it I added the action to the layout and its working thanks. – Hasan Zubairi Oct 24 '21 at 18:37
  • The popup is showing margin and padding around the popup. Any idea how can we remove that. – Hasan Zubairi Oct 24 '21 at 21:26
  • I think that margin can't be removed as it is being included by Salesforce when creating the popup for the quick action. – Óscar Gómez Balaguer Oct 25 '21 at 19:34
  • How can I add a init function. I want to check a condition and it yes do not want to show the popup and redirect to other page. Please help – Hasan Zubairi Nov 01 '21 at 17:11
  • You can check an example here https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_init_handler.htm – Óscar Gómez Balaguer Nov 01 '21 at 17:44
  • I checked it but it is not working for me. When I put the doInit function the buttons stop working. I put a question at stackoverflow. https://stackoverflow.com/questions/69791830/salesforce-lightning-component-init-function-call can you look at it please – Hasan Zubairi Nov 01 '21 at 18:20
  • I've answered your new question but you should do more debugging/checking prior to posting the questions. You will learn a lot also by doing so. – Óscar Gómez Balaguer Nov 01 '21 at 20:03