You need to sign in to do that
Don't have an account?
MikeCamp
Trigger firing in @futuer needs to do callout.
We are co-developing some code with a external vendor.
We wrote some custom code that when certain field on the contact are updated, it creates a record in a sync object(SyncLog).
Then there is a trigger that calls a @future method to send that object to an external system. This is required for callouts in triggers.
This is working fine, however we have NPSP installed.
When the address changes it kicks off a address validation process in the @future context. If the address gets validated, it updated the contact and the process creates the SyncLog (still in @future)
At this time we get an error - Future method cannot be called from a future or batch method.
So I figure this out and check for @future and call a method without @future.
Then we getan error
- Http post failed with exception Callout from triggers are currently not supported.
Due to our agreement we are trying to avoid any third party integration utilities.
The callout need to happen in near realtime.
We are caught in a Catch 22. Does anyone have any suggestions?
Here is a diagram of the problem:
Here is the pertinent code.
trigger Code
SVC_SyncLogService Code
We wrote some custom code that when certain field on the contact are updated, it creates a record in a sync object(SyncLog).
Then there is a trigger that calls a @future method to send that object to an external system. This is required for callouts in triggers.
This is working fine, however we have NPSP installed.
When the address changes it kicks off a address validation process in the @future context. If the address gets validated, it updated the contact and the process creates the SyncLog (still in @future)
At this time we get an error - Future method cannot be called from a future or batch method.
So I figure this out and check for @future and call a method without @future.
Then we getan error
- Http post failed with exception Callout from triggers are currently not supported.
Due to our agreement we are trying to avoid any third party integration utilities.
The callout need to happen in near realtime.
We are caught in a Catch 22. Does anyone have any suggestions?
Here is a diagram of the problem:
Here is the pertinent code.
trigger Code
if (!System.isFuture()) { SVC_SyncLogService.sendSyncLogFuture(new List<ID>(Trigger.newMap.keySet())); } else { SVC_SyncLogService.sendSyncLog(new List<ID>(Trigger.newMap.keySet())); }
SVC_SyncLogService Code
@future (callout=true) public static void sendSyncLogFuture(List<ID> SyncLogList) { try { sendSyncLog(SyncLogList); } catch (Exception e) { {exception code here} } } public static void sendSyncLog(List<ID> SyncLogList) { List<SyncLog__c> SyncLogRecordList = [{select goes here}]; //if running as part of a test class do not call manager if(!Test.isRunningTest()){ {vendorClass} Mgr = new {vendorClass}(); Mgr.sendSyncLog(SyncLogRecordList); } }
All Answers
It seems your IF ELSE logic has problem.
if (System.isFuture()) { //should ! sign be removed?
SVC_SyncLogService.sendSyncLogFuture(new List<ID>(Trigger.newMap.keySet()));
}
else {
SVC_SyncLogService.sendSyncLog(new List<ID>(Trigger.newMap.keySet()));
}
Second, I would put HTTP post code to sendSyncLogFuture method to try.
Third, I would add debug in the code below to check if both 'is future' and 'not future' are called when the trigger is triggered.