I have an apex method that returns a result in this form Map<String, List<Map<String,String>>> And I'd like to use this result localy to generate two dependent picklist. How can I call this method from my javascript code ? I haven't created the JS function yet.. Can someone tell me how to proceed ?


If you are using VF page then you can call it using action:function.

Apex method:

    public PageReference getMyMethod(){
    return null;

Visualforce page action function:

<apex:actionFunction action="{!MyMethod}" name="myFunction" />

actionFunction works like a javascript function, so you can call it from anywhere at your page like this:

<apex:inputField value="{!something}" onchange="myFunction()" />

and if you want call it from JavaScript button pls see this link


  • Thank you for your answer i understand now how to do the call.. In my JS function how can I put the result of my apex method in a variable ? Is it possible to do something like var res = myApexMethod(); ? – Joey Pablo Nov 12 '15 at 12:55
  • I have tried that and I get res = false ? i don't understand why.. – Joey Pablo Nov 12 '15 at 13:03
  • You can not assign the value like this. If you want to display it on VF page then you need to create getter method. which would be something like this -- getMyMethod, get keyword with your method name, so here myMethod will hold value and you can use on the page. – MIX DML Nov 12 '15 at 13:22
  • Can you explain more please ? should I create a getter method that returns a pageReference ? – Joey Pablo Nov 12 '15 at 13:36

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.