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
JSchneiderJSchneider 

How can I add a button to a visualforce page that executes onclickjavascript?

I have a perfectly working OnClick Javascript button already.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
 {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
  var scr="batchMaintenanceCalculator c = new batchMaintenanceCalculator (); " +
         " Database.executeBatch(c, 25); ";
  var result = sforce.apex.executeAnonymous(scr);
   alert("Maintenance amounts are being updated for all customers.");
I am now trying to relocate the button from my Account List View to the Home Page.  I believe the only way moving forward to accomplish this is to have a Visualforce Page with a button that executes the code above.  What would the code end up being on the VF page?
 
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. If you want to call apex class from button
http://sfdc.arrowpointe.com/2009/01/08/invoke-apex-from-a-custom-button-using-a-visualforce-page/

Sample code:-
http://salesforce.stackexchange.com/questions/12864/best-practice-for-calling-apex-methods-from-custom-button
{!requireScript("/soap/ajax/20.0/connection.js")} 
{!requireScript("/soap/ajax/20.0/apex.js")} 

var retStr; 
retStr = sforce.apex.execute("ApexClassName", "MyWebServiceMethodName", {Id:'{!Account.Id}'}); 

alert('The method returned: ' + retStr); 

document.location = '/{!Account.Id}';

CALL APEX CLASS FROM CUSTOM BUTTON (JAVASCRIPT) IN SALESFORCE
http://blog.shivanathd.com/2014/07/call-apex-class-from-custom-button-salesforce.html

Please let us know if this will help you

Thanks
Amit Chaudhary