本文介绍了如何从自定义按钮调用APEX方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为salesforce的Sales应用程序的机会"标签添加了自定义按钮.按下该按钮后,我想浏览一些新选项卡(通过添加适当的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,

在自定义按钮的javaScript"onClick"部分中添加以下Java脚本代码.

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';

注意:

  • 非常感谢亚当&杰里米·罗斯(Jeremy Ross)作为他们的向导,对我非常有帮助
  • 如果有人知道,请添加一些评论,我该如何检索机会"对象,而不是检索"Opportunity.Id",谢谢.
  • Thank you very much for Adam & Jeremy Ross for their guide, those arevery much helpful to me.
  • Please add some comment if any one know, how can I retrieveOpportunity' object rather than retrieve 'Opportunity.Id', thanks.

这篇关于如何从自定义按钮调用APEX方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 23:13