When Salesforce is life!

[Apex / JavaScript] What is @RemoteAction? Baby don’t hurt me, don’t hurt me, no more!

Spread the love

2 hours to find out why @RemoteAction was hurting me.
This is related to Cloudspoke’s challenge POC – Bootstrap Visualforce Pages (which I haven’t submitted neither).

This is the controller:

@RemoteAction
    public static List queryContacts(List filters, String orderBy) {
    ...
    }

And this is the piece of javascript:

  var orderBy;
  var filters = [];
  function searchContacts()
  {
   var ob = orderBy;
   Visualforce.remoting.Manager.invokeAction(
              '{!$RemoteAction.MyPageController.queryContacts}',filters,ob,
              function(result, event){
               
                  if (event.status) {
                   
                   //result has the List of contacts
                   var contacts = result;
                   console.log(contacts);
                  } else if (event.type === 'exception') {
                       alert(event.message);
                  } else {
                    alert(result+ ' '+event.message);
                  }
              }, 
              {escape: true});
  }

It keeps sayng:

Visualforce Remoting Exception: Method 'queryContacts' not found on controller CSChallenge.MyPageController. Check spelling, method exists, and/or method is RemoteAction annotated.

The problem is the javascript variable “orderBy” that is “undefined”!!

By initializing it with:

     var orderBy = '';

@RemoteAction go smoothly.


Courtesy of Doombringer

Previous

[Salesforce / Canvas] Set up a minimum Canvas App (Java style)

Next

[Visualforce / Tip] Always add a tag

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Powered by WordPress & Theme by Anders Norén