- 创建的Apex类应该是global, 方法应该是webservice
global class EnableButton {
webservice static String enableButtonBG(Id customId,Id accId)
{
// Do something
}
}
- JS Button:
{!REQUIRESCRIPT("/soap/ajax/45.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/45.0/apex.js")}
sforce.apex.execute是apex.js的一部分
sforce.apex.execute("EnableButton","enableButtonBG",{customId:'{!BGQuote__c.Id}',accId:'{!BGQuote__c.AccountNameId__c}'});
可以传参,(类名,方法名,参1,参2)
Reference:
http://blog.shivanathd.com/2014/07/call-apex-class-from-custom-button-salesforce.html
具体代码也可参见Github:JSButton直接调用Apex