2

I am writing a trigger on event . The trigger is working fine when a past activity(Event) is inserted(i.e when a event is inserted with past 'Start Date') . But when i insert a event record with future 'Start Date' it goes to open activity now whenever the event will finish a transition from open activity to activity history will be done. My Scenario is to fire the trigger when this transition occur.Is it Possible?

1 Answer 1

0

Not directly, as it doesn't appear the 'switch over' actually casues any updates, and the documentation for the Event object don't mention anything in particular about this.

Off the top of my head, the best way I can think of to do something when this happens is with batch apex and the System.scheduleBatch method. The algorithm would go something like:

  1. Find the nearest event in the future which will become in the past
  2. Calculate number of minutes to that event and schedule batch apex to run at that point
  3. Run batch apex and process all events which haven't been processed yet and are now in the past (remember, just because the batch is scheduled to run at a given time does not guarantee it will. You need to handle anything you may have missed)
  4. Go to step 1

There's obviously some edge cases here like what happens when you have no events that are in the future, and kicking off that initial job, but that's what your brain is for :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .