function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
esbium99esbium99 

Action Invoke doesn't seem to be working as advertised

If you look at the Apex Language reference pdf, on page 278, you will see an example of how to invoke an action from within another action.  This sounds great in theory but doesn't work in practice.  All we get is a system error like this:

 

 

Salesforce System Error: 1598249974-2475 (-814351657) (-814351657) An unexpected error has occurred. Your solution provider has been notified. (ApexPages)  

 To save you time, here is the code:

 

Controller:

 

public with sharing class Page2Controller { private ApexPages.Action saveAction = new ApexPages.Action('{!onSave}'); public Page2Controller() { } public PageReference doSomething() { saveAction.invoke(); return null; } public void onSave() { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'why dont I work?')); } }

 

Page:

 

 

<apex:page controller="Page2Controller" sidebar="false" showHeader="false"> <apex:messages /> <apex:form > <apex:commandButton action="{!doSomething}" value="doSomething" /> </apex:form> </apex:page>

 

Any Ideas?  This seems so simple, I am not sure what is going on.

 

Thanks in advance for any help you can provide!

 

 

 

 

 

Richie DRichie D

Hi,

 

I'm not sure why it doesn't work but it seems a weird thing to try and do...

 

You could just change your code to be:-

 

 

public with sharing class Page2Controller { public Page2Controller() { } public PageReference doSomething() { onSave(); return null; } public void onSave() { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'why dont I work?')); } }

 I'm sure there is a reson that this is available but I can't think of one off the top of my head. Do you have a reason for trying this or are you just going through the documentation?

 

R. 

 

esbium99esbium99

Richie,

 

I do have a reason for wanting this to work.  I am trying to have one action act as a proxy for all other actions to handle all my cross cutting concerns.  If I can execute actions dynamically, I can pass the action I want to execute as a param.

 

Thanks for your reply!

esbium99esbium99

Anyone else have any ideas on this?  I could really use some more insight into why this doesn't work.

 

Thanks in advance for the help!

dragonmagicldragonmagicl

Not that it is any solace, but I am getting this error now too. I have some old code dating back to June that uses this (and it used to work fine then). In the process of dusting it off however to finally go to production, it suddenly does not work anymore :(

 

I'll let you know if I find the solution.