Will the following trigger work ? - Salesforce Interview Question

Sample Code:

trigger tgrCounter on Mileage__c (after insert, after update) 
{
    List <Mileage__C> MilToupdate = new List<Mileage__C>();
    for(Mileage__cMlg : Trigger.new)
    {
        Mlg.Counter__c = Mlg.Counter__c + 1;
        MilToupdate.add(Mlg);
    }
    updateMilToupdate;
}

Answer:

No.
The reason is it will cause recursion.


Cheers!!!

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Trigger is recursive but not get run time exception by this..before that the exception is caused by using Trigger.new in after insert and after update.

    ReplyDelete