Newer Version Available
Apex in AJAX
To invoke Apex through anonymous blocks or public webservice methods, include the following lines in your AJAX code:
- Execute anonymously via sforce.apex.executeAnonymous (script). This method returns a result similar to the API's result type, but as a JavaScript structure.
- Use a class WSDL. For example, you can call the following Apex
class:
By using the following JavaScript code:
The execute method takes primitive data types, sObjects, and lists of primitives or sObjects.
To call a webservice method with no parameters, use {} as the third parameter for sforce.apex.execute. For example, to call the following Apex class:
Use the following JavaScript code:
Both examples result in native JavaScript values that represent the return type of the methods.
Use the following line to display a popup window with debugging information: