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
tinman44tinman44 

Calling Apex in Ajax?

Hey-
 
I am trying to write a simple method to call an APEX script from JavaScript...to learn how it functions (so my code does not do anything). I feel like I have followed the instructions...but I keep getting this error:
 
Code:
{faultcode:'soapenv:Client', faultstring:'No service available for class 'webserviceTest'', }

 Here is my class:
 
Code:
global class webserviceTest {

 webservice static String getAccounts(Id userId) {
 
  String Name = 'TEST';
  return Name;
 }
}

Here is my s-control:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/11.0/connection.js"></script>
    <script src="/soap/ajax/11.0/apex.js"></script>
<script type="text/javascript">

function init() {


try {

 var accts = sforce.apex.execute("webserviceTest","getAccounts",{userId:"{!$User.Id}"});

} catch (e) {

 document.getElementById('test').innerHTML = e.toString();

}
 alert(accts);

}


</script>

</head>
<body onload="init()" id='test'>
</body>
</html>

 
Am I missing something? Thanks in advance for any help!



Message Edited by tinman44 on 06-02-2008 12:21 PM
cheenathcheenath
Is there a namespace defined for your org? If so, you have to prefix the class name with it.

sforce.apex.execute("namespace.webserviceTest","getAccounts",{userId:"{!$User.Id}"});



AkiTAkiT
I was having this issue today and already frustrated as I was sure my code was otherwise ok!

Thanks for this valuable info!!