You need to sign in to do that
Don't have an account?

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?
Thanks all for taking a look.
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?
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")} try{ var acct = '{!Account.Id}'; var sec = sforce.apex.execute("SecurityCheck","SecurityCheck",{acct:acct}); var show = sforce.apex.execute("SecurityCheck","sec.showPage",{}); //alert(show); } catch(err){ var txt = "Error: "; txt+=err.description+" 11"; alert(txt); } If (show == true) { window.open('ThisURL'); } else { window.open('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'});
location.reload(true);
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm.
Hope this helps.