0

So it's simple i have a list button on an object that executes JS to do

updatePeripherals()

Which simply runs an apex method.

Now my solution would just be to create a VF page that runs the script and assign that to a lightning quick action. IE create a button to work in lighting on the standard related list of a record. Now i add SVC_CR_Package_Ctl because the method i want to run is in that apex class.

<apex:page standardController="SVC_Operations__c" extensions="SVC_CR_Package_Ctl" >
    <apex:form >
        <script>
        updatePeripherals()

        </script>
    </apex:form>
</apex:page>

Which hopefully would run this method, which is part of a global with sharing class.

public PageReference updatePeripherals()
{
    try {
        SVC_PKG_Service.deployPeripherals(this.packageObj.Id, this.packageObj.Change_Request__r.Account__c);
    } catch (Exception e) {
        handleException(e, null, 'Deployment failed');
    }

    // page refresh is required because we need to refresh related lists (which cannot be rerenderd) and package header (which also cannot be rerendered)
    PageReference pr = new PageReference('/apex/SVC_CR_Package?id=' + this.packageObj.Id);
    pr.setRedirect(true);
    return pr;
}

Now you can see in the try it runs another method in a different class, which is a public with sharing class SVC_PKG_Service. This one also has multiple methods on multiple objects.

Cool easy right, not really. Because I'm realizing this is a list button. Meant to be on the related list of another object, but it does not need "Display Checkboxes (for Multi-Record Selection)". But when i try to create a list button that would run by VF page...there's nothing their, it appears as an option everywhere else but not there.

What am i missing, also would it be better to make this a lightning component instead...? Can a lightning component do what i want without having to put in loads of dev time (because i have to convert like 40 other buttons just like this, so i'm looking for the easiest way of getting this working in lightning)

EDIT: now that i thought about it for five seconds i'll probably just do action="{!updatePeripherals()}"> or something on the page but yeah.

1

There are a couple of things that will help with your approach:

1) To call an apex function from VF you don't use javascript. You can either add a button in the page (<apex:commandButton action="{! updatePeripherals}" value="Update"/>), call it using an actionFunction (see here) or add it on the action (onload) of your page (<apex:page action="{! updatePeripherals}"..../>)

2) In order to be able to add a VF page to a List button, you must implement the standard controller. I won't copy the entire answer, but this SFSE answer explains it in detail

You have to add <apex:page standardController="YourObject__c" recordSetVar="yourRecords">, even if you do not plan to use the functionality that the standard controller provides.

| improve this answer | |

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.