I have a @RemoteAction method which return a List of opportunities via a SOQL statement that needs to use the dynamic 'WHERE Account.Id =: ApexPages.currentPage().getParameters().get('id')'.

This wasn't working though because it transpires, as per the docs, that JavaScript remoting is async and therefore, there is no PageReference context.

The solution apparently, as per ApexPages.currentPage().getParameters with javascript remoting, is to pass the parameter(s) explictly to a a method from JavaScript.

My code is below and although I am not getting any errors when I save the respective VF page (it's actually a VF component, but I don't think that matters) or the method, the data is not being displayed as expected on the Visualforce page.

Can someone please advise?


  @RemoteAction //Remote Action to expose method to JavaScript Remoting
public static List<Opportunity> getDatatable(Id accountid){
   return [select name, stagename, createddate, amount from Opportunity WHERE Account.Id=: accountid ORDER by Name ASC ];

 "fnInitComplete": function(oSettings) { 
                  ChartController.getDatatable('{!$currentPage.parameters.id}')(function(result, event){

FYI to readers: another good sources to read: Do RemoteAction methods have access to page parameters?


Remote action can be called with following syntax.

<script type="text/javascript">
    "fnInitComplete": function(oSettings) { 

        var recordid='{!$currentPage.parameters.id}';
            function(result, event){
                if (event.status) {

                    //your success code

                } else if (event.type === 'exception') {
                    //Your exception handling
                } else {

            {escape: true}
| improve this answer | |
  • Thanks Himanshu. I am returning this error 'No remoted actions found to resolve '$RemoteAction.ChartController.getDatatable'. Any idea? Thanks – Andy Hitchings Nov 12 '15 at 14:47
  • in which controller you have defined your remote action? – Himanshu Nov 12 '15 at 14:49
  • Ah - sorry, I think I know what the problem was...It was a component that was marked as <apex:component>...I have now added <apex:component controller="ChartController"> – Andy Hitchings Nov 12 '15 at 14:51
  • that is correct :) – Himanshu Nov 12 '15 at 14:52
  • Fantastic - this is working now. Many thanks, Himanshu. – Andy Hitchings Nov 12 '15 at 14:52

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.