I've started work on implementing Visualforce pages to use in list view buttons using the approach How to convert mass actions on list view records from Classic to Lightning Experience?. We have many of these buttons, and they have lots in common to such an extent that there are just two constants that need to change from button to button. So while I need to create many pages, most of the rest of the code can be common.
The first approach was to do most of the work in a common component so each page could set the appropriate constants:
<apex:page
standardController="MyObject__c"
extensions="MyController"
recordSetVar="unused"
>
<c:ListActions
...
operation="MyObjectActions.move"
value='last'
...
/>
</apex:page>
and that works fine for cases where the page is displayed.
But now for some cases, I'd like to not render the page. That can be done via the apex:page action
attribute, once the work is done, returning the StandardSetController cancel()
PageReference to go back to the list view page:
<apex:page
standardController="MyObject__c"
extensions="MyController"
recordSetVar="unused"
action="{! init }"
>
</apex:page>
My problem is how to inject the two constants for this case. About the only attribute of apex:page
that perhaps I could abuse is the extensions
, but I'd have to create multiple marker classes. Or I could add many methods to the controller that set the required permutations of the constants. Or is there a better way to go?
PS
It isn't elegant but I guess I can live with:
<apex:page
standardController="MyObject__c"
extensions="MyController"
recordSetVar="unused"
action="{! execute_BenefitActions_move_last }"
>
and:
public PageReference execute_BenefitActions_move_first() {
return execute('BenefitActions.move', 'first');
}
public PageReference execute_BenefitActions_move_up() {
return execute('BenefitActions.move', 'up');
}
public PageReference execute_BenefitActions_move_down() {
return execute('BenefitActions.move', 'down');
}
public PageReference execute_BenefitActions_move_last() {
return execute('BenefitActions.move', 'last');
}
...
private PageReference execute(String operation, String value) {
this.operation = operation;
this.value = value;
...
But before I add this ugliness, if you have a better approach, please share.
PPS
Query string parameters can't be used in this case - see Is a "Content Source" of "Visualforce Page" required for Ids for the checked list view items to be received by a StandardSetController?
standardController="MyObject__c"
./apex
all the time. If you are advertising to that, assuming I understand your requirement, create pages say Constant1, Constant2, Constant3. The sole purpose of those pages would be to redirect to the final page passing in the parameters. You could use a single controller, determine the Page name hit, then redirect to the main page with the appropriate parameters. This preserves the "Visualforce Page" of the button and removes the/apex
as each button would hit the appropriate ConstantX redirect.