当前位置:K88软件开发文章中心编程语言非主流编程语言Apex → 文章内容

Apex - 调用

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 16:30:56

由 kaikai0220 创建,youj 最后一次修改 2016-12-12 Apex调用是指执行Apex类的过程。 Apex类只能在通过以下方法之一调用时执行: 触发器和匿名块为指定事件调用触发器。 异步Apex调度Apex类以按指定的时间间隔运行,或运行批处理作业。 Web服务类Apex电子邮件服务类Apex Web服务,它允许通过SOAP和REST Web服务公开您的方法。 Visualforce控制器Apex电子邮件服务来处理入站电子邮件。 使用JavaScript调用Apex Ajax工具包,用于调用在Apex中实现的Web服务方法。 我们将看看调用的Apex一些常见的方式。 执行匿名块您可以通过开发者控制台中的execute anonymous调用Apex类,如下所示: 步骤1:打开开发者控制台 步骤2:单击调试。 第3步:执行匿名窗口将如下所示打开,然后点击执行按钮: 第4步:打开调试日志,它将出现在日志窗格中。 触发器您也可以从Trigger调用Apex类。 当指定的事件发生时触发器被调用,触发器可以在执行时调用Apex类。 下面是一个示例代码,显示当调用Trigger时类如何被执行。 例如://Class which will gets called from triggerpublic without sharing class MyClassWithSharingTrigger { public static Integer executeQuery (List<apex_customer__c> CustomerList) { //perform some logic and operations here Integer ListSize = CustomerList.size(); return ListSize; }}//Trigger Codetrigger Customer_After_Insert_Example on APEX_Customer__c (after insert) { System.debug('Trigger is Called and it will call Apex Class'); MyClassWithSharingTrigger.executeQuery(Trigger.new);//Calling Apex class and method of an Apex class}//This example is for reference, no need to execute and will have detail look on triggers later chapters.从Visualforce则页面控制代码Apex类也可以从Visualforce页面调用。 我们可以指定控制器或控制器扩展,并且指定的Apex类被调用。 例如: VF页面代码: Apex类代码(控制器扩展)

Apex - 调用