2

I wrote triggers that will be fired after inserting/updating/deleting task and event. What the triggers do is HTTP call out. When a lead is convert, tasks and events will be copied too, so the triggers are fired and give a "too many future task" exception.

After discussing with my project manager, we decided that, on lead conversion, copying tasks and events is required but the HTTP callout triggers are not.

I don't want the triggers to be fired on lead conversion. What should I do? Or how could the task/event trigger check that a user is converting a lead.

According to this page Understanding Lead Conversion I tried disabling validation and triggers for lead convert. But the task and event triggers were still fired. (I think only lead/account/contact/opportunity's trigger were disabled.)

Any help would be appreciated.


My solution:

According to this page, I think, when a lead is converted, an account/contact/opportunity will be created before lead.InConverted is changed to true. I tried creating triggers to test the conversion flow. The test result shown below.

Trigger on Account is fired. Triggers on Task/Event are fired. Trigger on Lead is fired.

So, I create a class which contains only a static boolean like checkLeadConvertIsInProgress == false. And in a trigger on Account, I set checkLeadConvertIsInProgress == true.

When the trigger on Task is fired, the trigger will check on checkLeadConvertIsInProgress, if true, skip the HTTP callout, otherwise do the callout.

Thank you for all your helps!

  • So you are copying tasks and events from Lead to become tasks/events under Account/Contact/Oppo ? If so, then the DML that does the copy can set a custom field in Task object: is_originated_from_lead_conversion__c and your Task trigger code can skip doing its work if this is true (you'll have to decide how to deal with subsequent DML at a later time on same Task and whether trigger work is disabled as well. – cropredy Jun 14 '14 at 9:37
  • 1
    You could use a Trigger on Lead that checks for IsConverted==True. Then when Tasks or Events are being triggered for the corresponding Contact you could bypass the trigger in the same transaction. Set a static boolean in a class that can be used to indicate the lead conversion is in progress. – Daniel Ballinger Jun 14 '14 at 10:22
  • @crop1645 Thank you! I think I have the idea how to do it. And then the task/event trigger after insert can switch is_originated_from_lead_conversion__c to fault later. – lw29 Jun 14 '14 at 11:55
  • @DanielBallinger Thank you. I will look into IsConverted and the use of static boolean. Great advice! – lw29 Jun 14 '14 at 12:03
2

You could use a Trigger on Lead that checks for IsConverted == true. Then when Tasks or Events are being triggered for the corresponding Contact you could bypass the trigger in the same transaction. Set a static boolean in a class that can be used to indicate the lead conversion is in progress.

  • May I ask when lead.IsConverted is set to true? I tried writing a trigger on lead before update but the trigger on task after update is fired before the trigger on lead. – lw29 Jun 16 '14 at 2:12
  • Thank you again. I solved the problem using your advice. :) – lw29 Jun 16 '14 at 2:57
  • Great, how did you get round the IsConverted not being set until after update? – Daniel Ballinger Jun 16 '14 at 3:00
  • 1
    I added the solution to my post. I use the static boolean variable as you told me, and set it to true after an Account is created so I can pass the variable to the following trigger process on task creation. – lw29 Jun 16 '14 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.