[SalesForce] Convert javascript button to quick action

We need to convert some buttons to lightning quick actions to have on the lightning experience. I'm having a difficult time designing an adequate solution.

Current Button Functionality:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")} 
var result = sforce.apex.execute("CloneObject","cloneQuote",
    {
        objectId:"{!Quote.Id}", 
        cloneAttachments: true
    }); 

window.open(result + '/e?&retURL=' + result + '&saveURL=' + result);

This calls out to a piece of APEX code in a class called CloneObject and runs a method called cloneQuote. This is custom clone functionality because we would like to clone related objects as well.

Lightning Quick Action Functionality:

I ventured down the path of a VisualForce quick action, but it's unnecessary for a modal window to open. It just needs to be a button.

Is there an elegant quick action alternative for calling out to a piece of apex code?

Best Answer

I think no matter what kind of Quick Action you do, native or customized, it will always open a modal window in Lightning.

You could create a small VisualForce page or Lightning component to add directly to the Lightning page layout, which simply hosts a button that carries out the desired action. That may be the only way to put a one-click action inside the layout.

Here is another thought: Create a native Quick Action that creates a record copying over whatever fields you want as Predefined Values, and allows them to edit any they want to. This will display as a modal dialog, replacing the Edit page they'd get patched through to. But also set a Predefined Value in text field that is hidden from the Action layout. This hidden value would be the ID of the record you clone. Now you can set an Apex trigger that states, if a record is created with a value in the hidden field, run your custom code that clones the child objects.

Related Topic