function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anand SenguntharAnand Sengunthar 

Hi All, I am trying to call apex from javascript. Wrote the below script

Hi All,
 I am trying to call apex from javascript.  Wrote the below script

<script src="/soap/ajax/15.0/connection.js" type="text/javascript">
</script> <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
var r= confirm ("Are you sure you want to fetch?");
if(r== true)
{
   var a = sforce.apex.execute("web","fetch",{ID: "{!Account.Id}"});
   alert(a);
}
else
{
   alert("Operation aborted");
}

I have already the class named 'web' with method 'fetch'.  I wrote the above script on a button.  When I click on that button,  I get an error 'Unexpected token < '
On debugging , i found issue with the two lines defining the ajax connection and apex.js.  can anyone help what is wrong with the code.
BenazirBenazir
Hi Anand,

You have to define the ajax connection and apex.js in below format.

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

Thanks,
Benazir