0

我希望在添加/删除/修改附件对象时触发顶点触发器。当此触发器触发时,我想通过一个顶点类传递附件的父 ID,该类将该 ID 传递给外部网站上的 PHP 页面(使用 GET 很好)。

我不必显示PHP 页面,我只需要运行 PHP 页面。php 页面只是将 ID 存储在 MySQL 数据库中。我也不需要知道附件发生了什么(如果它被添加/删除/修改)。

非常感谢您提供的任何帮助。我尝试了几种不同的方法,但我只是遇到了很多我每次都无法弄清楚的错误。我认为我的任何尝试都不值得在这里分享。

非常感谢!

4

1 回答 1

2

为了让调用在触发器中起作用,您需要再做一步:@future-Call。这意味着,在您的触发器中,您必须收集所有插入/更新/删除的 ID。然后,您必须创建一个使用 @future-Annotation 实现静态 void 的类(因此,此函数始终异步执行)。最后,您从触发器调用此函数并在函数中运行您的标注。

trigger Attachment_AfterAll_Callout on Attachment (after insert, after update, after delete) {
    Set<Id> ids = new Set<Id>();
    //collect your ids here
    //you might get away with just using ALL ids: ids = Trigger.newMap.keyset()
    //call @future Function
    WebserviceHandler.attachmentCall(ids);
}

在类文件中:

public class WebserviceHandler {
     @future(callout=true)
     public static void attachmentCall(Set<Id> ids) {
         //make your WS Callout here. 
         //Note, this is not guaranteed to run inline with the trigger,
         //execution may be delayed!
     }
}

请注意,您可能运行的 @future 调用数量是有限制的,因此您应该批量执行。

于 2013-10-11T22:46:00.733 回答