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
jonathanbernddf20131.387825590468351E12jonathanbernddf20131.387825590468351E12 

Javascript button to call apex method help

I've written a trigger and class that work currently off a checkbox being true on the parent object. Now I'd like to replace this checkbox with a button 'Publish'.  Could you help me figure out where the 'missing link' is between my very rudimentary js and my method. I know the button is on an object, but I'm not seeing exactly how to tell the button execute the method on this record on this SObject now.

Here's the beginnings of my js.
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var pubApp = sforce.apex.execute("PubVersionNumber", "buttonVersionNumber", {});
window.alert("App is Published." );

 
Best Answer chosen by jonathanbernddf20131.387825590468351E12
jonathanbernddf20131.387825590468351E12jonathanbernddf20131.387825590468351E12
Thanks for the help. Fixed it with a tweak and your link sfScott
​{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var result = sforce.apex.execute("PubVersionNumber","buttonVersionNumber",{});
alert("App is Published." );
window.location.reload();

 

All Answers

sfScottsfScott
I don't see anything wrong with your JS based on:  http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm
Simple question would be if you declared your buttonVersioNumber method as 'webservice static'?
At the bottom of the link it says: Use the following line to display a popup window with debugging information:
   sforce.debug.trace=true;

Perhaps that will give you a line where to go?

 
Ruwantha  LankathilakaRuwantha Lankathilaka
If you need a button why can't you simply use apexCommandButton

<apex:commandButton action="{!myApexMethod}" value="publish" id="theButton"/>

If there is any problem you can use simply use actionFunctions
See the following example.(not tested)


<input id="theButton" type="submit" name="theButton" value="Publish" />
<apex:actionSupport event="onclick" action="{!myApexMethod}" />



 
jonathanbernddf20131.387825590468351E12jonathanbernddf20131.387825590468351E12
Thanks for the help. Fixed it with a tweak and your link sfScott
​{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var result = sforce.apex.execute("PubVersionNumber","buttonVersionNumber",{});
alert("App is Published." );
window.location.reload();

 
This was selected as the best answer