0

Which method is typically used to convert an on click javascript detail page button which utilizes the AJAX toolkit? Looking to call the "forwardEmails" method with the case ID and default value for settings name upon a click.

{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")} 

sforce.apex.execute("EmailUtility","forwardEmails",{caseId:"{!Case.Id}",settingsName:"Default"}); 
location.reload();
1

You just need three code parts: changing the Apex code, creating the component, and creating the controller.

Apex

Add @AuraEnabled to your method.

@AuraEnabled public static void forwardEmails(Id caseId, String settingsName) {
  // original code here //

Component

It needs to be a quick action component.

<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" 
                controller="EmailUtility">
  <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

Controller

({
   doInit: function(component, event, helper) {
     var action = component.get("c.forwardEmails");
     action.setParams({ caseId: component.get("v.caseId"), settingsName: "Default" });
     action.setCallback(this, function(result) {
       // Refresh the data
       $A.get("e.force:refreshView").fire();
       // Close the quick action
       $A.get("e.force:closeQuickAction").fire();
     });
     $A.enqueueAction(action);
   }
})

From here, create a new Quick Action (Setup > Object Manager > Cases > Buttons, Links, and Actions > New Action). Select the component you just created for the quick action. After this, add the quick action to the page layout.

There are a few more "extra" pieces you could add (check the documentation for details), but this is the absolute bare-minimum that you need to change to perform the conversion.

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.