4

I have some unmanaged code that creates child records to be attached to a Lead record after insert. Unfortunately, my org contains some managed code that also runs on a Lead after insert, and it's imperative for the unmanaged code to run before the managed. With that said, I know the order in which triggers execute on the same object for a given event is undefined.

My question pertains to the scenario where the managed trigger fires first. The managed code looks for duplicate records based on set criteria and merges the two if one is found. The existing record will always be the master and the incoming Lead will be deleted.

What can I expect to happen in the unmanaged after insert trigger that fires after the managed trigger has deleted the record? Is it even executed at all? Will the deleted records have their MasterRecordId set to the ID of the surviving record?

  • Well, if the lead is being deleted, you can just write some trigger code on after delete instead no? – willard Feb 14 '14 at 21:21
  • @willard I thought of that initially, but if the managed code does not merge anything due to the nonexistence of a duplicate record the delete event won't be triggered. – Brian Feb 14 '14 at 21:28
  • So write code on both after delete and after insert. Both events can call the same method. Check before running the code on after insert that the record actually exists and you should be set. – willard Feb 16 '14 at 14:18
1

The record that was delete will have all future transactions removed and not executed. This only applies to transactions directly caused by the deleted record.

The reason I am saying this is:

  1. I had a trigger once that caused a rollback of the database before the transaction was completed and all records that were rolled back were not present in the remaining record lists nor were the ids sent to the future methods.

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.