课程表

Apex课程

工具箱
速查手册

Apex - 调用

当前位置:免费教程 » 程序设计 » Apex

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时类如何被执行。


例如:

  1. //Class which will gets called from trigger
  2. public without sharing class MyClassWithSharingTrigger {
  3. public static Integer executeQuery (List<apex_customer__c> CustomerList) {
  4. //perform some logic and operations here
  5. Integer ListSize = CustomerList.size();
  6. return ListSize;
  7. }
  8. }
  9.  
  10. //Trigger Code
  11. trigger Customer_After_Insert_Example on APEX_Customer__c (after insert) {
  12. System.debug('Trigger is Called and it will call Apex Class');
  13. MyClassWithSharingTrigger.executeQuery(Trigger.new);//Calling Apex class and method of an Apex class
  14. }
  15.  
  16. //This example is for reference, no need to execute and will have detail look on triggers later chapters.

从Visualforce则页面控制代码

Apex类也可以从Visualforce页面调用。 我们可以指定控制器或控制器扩展,并且指定的Apex类被调用。


例如:


VF页面代码:


VF页面代码


Apex类代码(控制器扩展)


Apex类代码
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号