如何从自定义按钮调用 APEX 方法 [英] How invoke APEX method from custom button
本文介绍了如何从自定义按钮调用 APEX 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为 salesforce 的销售应用程序的机会"选项卡添加了自定义按钮.按下该按钮后,我想导航一些新选项卡(我已通过添加正确的 URL 来完成)并执行以下 Apex 方法.如何执行此方法.谢谢.
I have add custom button for salesforce's Sales application's 'Opportunities' tab. Once press that button I want to navigate some new tab (I have done it by adding proper URL) and execute following Apex method. How can execute this method. Thanks.
public class JobService {
private JobDao job_dao = new JobDao();
public void insertJob() {
Job__c newJob = new Job__c();
job_dao.insertJob(newJob);
}
}
推荐答案
我已经通过以下方式完成了这个任务,
I have accomplished this task as following way,
将以下 java 脚本代码添加到自定义按钮的 javaScript 'onClick' 部分.
Add following java script codes to, custom button's javaScript 'onClick' section.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
//Get Opportunity id
var opId= "{!Opportunity.Id}";
//Call insertJob method by passing that Opportunity id
sforce.apex.execute("JobService","insertJob",{op_id:opId});
//Redirect to that tab
window.location = 'https://ap1.salesforce.com/a0G/o';
注意:
- 非常感谢 Adam &Jeremy Ross 作为他们的向导,那些是对我很有帮助.
- 如果有人知道,请添加一些评论,我如何检索Opportunity' 对象,而不是检索 'Opportunity.Id',谢谢.
这篇关于如何从自定义按钮调用 APEX 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文