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
Ben MorchBen Morch 

Call Apex class from custom button/link with JavaScript

Hello All,

I am trying to call a custom class from a link on the Account object using Execute JavaScript.  Ultimately I want to call the SecurityCheck class with a parameter of the account Id to instantiate the "sec" variable.  Then set the "show" variable to the results of sec.showPage().  I am doing something wrong here as I am not very good with JavaScript.  Once I have show = true || false then I will direct to one of two URLs.

My questions are:
1) How do I properly instantiate a variable in JavaScript by calling a class constructor with a parameter?
2) How do I then call a method of that class (class.showPage)?
3) Is there a better way to do this?  Like JS on the VF page that I am directing to?

    var acct = '{!Account.Id}';
    var sec = sforce.apex.execute("SecurityCheck","SecurityCheck",{acct:acct});

    var show = sforce.apex.execute("SecurityCheck","sec.showPage",{});  

    var txt = "Error: ";
    txt+=err.description+" 11";

If (show == true) {'ThisURL');
} else {'ThatURL');

Thanks all for taking a look.

Define class with webservice 
 WebService static void updateStatus(Id RecordID, String status) {      
//add logic here

In javascript call similar to following syntax
sforce.apex.execute("Utils","updateStatus",{ID:"{!object.Id}", String:'Submit'});
You can also refer to
Hope this helps.