Print this page

Error - "No remoted actions found to resolve $RemoteAction.XXX.action" when loading dynamic scripts with remoting

Knowledge Article Number 000194030
Description
Scenario-
User loads a script dynamically in a VF page.
Layout is set to "none", for each child element with the rendered attribute set to some value in a variable.
While the content isn't visible, JavaScript can still access the elements through the DOM ID, making it possible to update the child elements

Sample code-
VF Page
#########################
<apex:page controller="MyController">
<apex:outputPanel layout="none" rendered="{!myVar = 0}">
<apex:form >
<apex:actionFunction name="bump" action="{!bumpRerender}" rerender="borken" />
</apex:form>
<script>bump();</script>
</apex:outputPanel>

<apex:outputPanel layout="none" rendered="{!myVar > 0}" id="borken">
<script>alert('Inner alert: {!$RemoteAction.MyController.action}');</script>
</apex:outputPanel>
</apex:page>
#########################

Apex class- MyController

 
public with sharing class MyController { 

public Integer myVar {get; set;} 

public MyController() {  myVar = 0;  } 

public void bumpRerender() {  myVar++;  } 

@RemoteAction  public static void action(){  } 
}
#########################
 
Issue- User gets following error when the VF page is executed-
No remoted actions found to resolve '$RemoteAction.MyController.action' 
Resolution
You shouldn't try to load scripts dynamically after the page load without a very good reason, and this is true of any website you develop, not just Visualforce. Even so, you doubly shouldn't try to use expressions of any sort in a script that is rendered dynamically, because it can cause all sorts of unusual errors to crop up (and not just with remoting). 
 
If you remove the script tag <script>bump();</script> the same code works fine. While it's true that expressions are allowed within script blocks, they are generally fraught with pitfalls that would be avoided if one simply remoted exclusively; you no longer have to worry about proper escaping and order of re-render execution. 
 
The Visualforce library avoids overwriting existing functions and the function is rendered out of existence in the view state once it is hidden, thus causing the crash you've observed. 
 
This is working as designed. 




promote demote