• Matt Higel 13
  • NEWBIE
  • 0 Points
  • Member since 2015


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I have a debugged my trigger down to the barest code, and have some strange behavior that I need help to get sorted.

When I create a new Contact using the following trigger:
trigger ContactTrigger on Contact (before insert, after insert) {
	System.debug('1');
	if(Trigger.isBefore) {
	        System.debug('2');
		if(Trigger.isInsert) {
			System.debug(3');
		}
	}
	if(Trigger.isAfter) {
		System.debug('4');
		if(Trigger.isInsert) {
			System.debug('5');
		}
	}
	System.debug('6');
}
I would expect to see a debug statement for each number from 1-6.  However, numbers '4' and '5' do not print, which seems to indicate that the After Insert event is not firing for the Contact object.

If I remove the Before Insert event and create a Contact:
trigger ContactTrigger on Contact (after insert) {
	System.debug('1');
	if(Trigger.isAfter) {
		System.debug('2');
		if(Trigger.isInsert) {
			System.debug('3');
		}
	}
	System.debug('4');
}
Then numbers from 1-4 are correctly output to the debug log (i.e. the After Insert event is firing).

There are no compilation errors, and no errors in the debug logs.  In either version of the trigger, a Contact record is created.  I can validate that After Insert behavior on the Contact object does execute as expected in other sandboxes for my org.

If there's an issue with the above code that would explain the behavior, then I'm missing it.
I have a debugged my trigger down to the barest code, and have some strange behavior that I need help to get sorted.

When I create a new Contact using the following trigger:
trigger ContactTrigger on Contact (before insert, after insert) {
	System.debug('1');
	if(Trigger.isBefore) {
	        System.debug('2');
		if(Trigger.isInsert) {
			System.debug(3');
		}
	}
	if(Trigger.isAfter) {
		System.debug('4');
		if(Trigger.isInsert) {
			System.debug('5');
		}
	}
	System.debug('6');
}
I would expect to see a debug statement for each number from 1-6.  However, numbers '4' and '5' do not print, which seems to indicate that the After Insert event is not firing for the Contact object.

If I remove the Before Insert event and create a Contact:
trigger ContactTrigger on Contact (after insert) {
	System.debug('1');
	if(Trigger.isAfter) {
		System.debug('2');
		if(Trigger.isInsert) {
			System.debug('3');
		}
	}
	System.debug('4');
}
Then numbers from 1-4 are correctly output to the debug log (i.e. the After Insert event is firing).

There are no compilation errors, and no errors in the debug logs.  In either version of the trigger, a Contact record is created.  I can validate that After Insert behavior on the Contact object does execute as expected in other sandboxes for my org.

If there's an issue with the above code that would explain the behavior, then I'm missing it.