Book Image

Learning Apex Programming

Book Image

Learning Apex Programming

Overview of this book

Table of Contents (17 chapters)
Learning Apex Programming
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

JavaScript buttons jubilee


A neat side effect of the SOAP web service methods we just wrote is that they are now accessible via JavaScript thanks to the AJAX toolkit. What this means to you is that if you have a very simple operation to perform, where going to the edit page is a nuance and a Visualforce page is overkill, you can create an OnClick JavaScript button. The following snippet is your template:

//Required Import Statements
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}

//Call your method, replace variables as needed
sforce.apex.execute("CLASS NAME", "METHOD NAME",{PARAM : '{!VALUE}' });

//Refresh the page to show updates to current record
location.reload(true);

Tip

If you are not actually modifying data on the current view page, you can omit the location reload. Refreshing the page is only required so that any data updates your web service method does to the current record you are viewing are visible once the process completes.

Here...