4

In the code below, the alert doesn't work. If the I take out the loadleads function, then the alert does work. What's the issue?

<apex:page showHeader="true" sidebar="false" controller="LeadSearchJS">
<head>
<script type="text/javascript">
function saysomething() {
    alert ("said something.  Don't give up on me.");
}
function loadLeads(){   Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.LeadSearchJS.findAll}',
}                                                 
</script>
</head>

<body>
<div>
    Oh Hai.
    <div id="leadTable">
        <p>
            <a href="#" onClick="saysomething();">Say Something.  I'm giving up on you.</a>
        </p>
    </div>
</div>
</body>

</apex:page>

Here is the controller:

global with sharing class LeadSearchJS {

@RemoteAction
global static List<Lead> findAll() {
    return [SELECT Id, Email FROM Lead];
}
}

1 Answer 1

5

The loadLeads javascript function is broken, which causes other javascript on your page to break.

function loadLeads() {
    Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.LeadSearchJS.findAll}',
}  

The invokeAction function you are calling has no closing parenthesis. There is also no callback function. It should be more like:

function loadLeads() {
    Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.LeadSearchJS.findAll}', function(result, event) {
        console.log('result', result);
        console.log('event', event);
    });
}  
2
  • Thanks a lot! Awesome. Quick followup question - I had read that using this method does not count against API usage limits, is that true? I see it counting against API calls in system overview/etc.
    – Chris
    Commented Feb 25, 2015 at 15:12
  • 1
    So it looks like it does NOT count against the API call limit, after testing. But in case some don't know, the Developer Console DOES count against the API call limit! How very odd.
    – Chris
    Commented Feb 25, 2015 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .