You need to sign in to do that
Don't have an account?
everlongh
How can I stop a trigger executing from a web service api call?
This must be easy, but I've tried several approaches and haven't succeeded yet. My integration server makes a web service API call to update an Opportunity from our external application, then my Opportunity trigger fires on the update causing a callback to my integration server, so I get more than one API call. Here's the relevant part of the trigger code: trigger outboundOpportunity on Opportunity (before insert, before update, after insert, after update) { if(trigger.isAfter && TriggerUtility.isFutureUpdate != true) { SObjectType type = trigger.new[0].getSObjectType(); Schema.DescribeSObjectResult d = type.getDescribe(); IntegrationCallout.alertIntegration(d.getName(), trigger.new[0].ID); } else ... The approach I tried is described in some blog posts below using a static variable but the trigger still fires: http://www.tehnrd.com/apex-flow-control-preventing-infinite-loops/ http://blog.jeffdouglas.com/2009/10/02/preventing-recursive-future-method-calls-in-salesforce/ I'm stuck because the call originates from the integration server so neither of these approaches will work. The other approach I'm thinking of trying is to add a custom field and only populate it from the API so the trigger would look like this: trigger outboundOpportunity on Opportunity (before insert, before update, after insert, after update) { for(Opportunity o : trigger.new) { String fromAPI = o.FromAPI__c; if(trigger.isAfter && fromAPI != '") { SObjectType type = trigger.new[0].getSObjectType(); Schema.DescribeSObjectResult d = type.getDescribe(); IntegrationCallout.alertIntegration(d.getName(), trigger.new[0].ID); } } else ... Obviously the field would need to be reset after the update. Can someone tell me if this will work or is there a better way? |