I have written a trigger which needs to perform some logic only after insert, and some logic only after an update.

I have defined my Trigger as (after insert, after update). How can I control the execution of the trigger code depending on whether it was an insert or an update event?


You have a trigger, and you want one piece of code to run when the trigger is after insert and a different piece of code to run when it is after update?

trigger MyFirstTrigger on Account (after insert, after update) {

   if (Trigger.isAfter) {
       if (Trigger.isUpdate) {
           // do the after update related functionality
       if (Trigger.isInsert) {
           // do the after insert related functionality

  • 2
    @Dougb your understanding of English is awesome! :P – Martin Borthiry May 20 '13 at 11:00

Your Answer

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