トリガー内からコールアウトを機能させるには、もう 1 つの手順を実行する必要があります。@future-Call です。つまり、トリガー内から、挿入/更新/削除されたすべての ID を収集する必要があります。次に、@future-Annotation を使用して static 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 Call の数には制限があるため、実行をバッチ処理する必要があることに注意してください。