+ Start a Discussion
Lisa Horne 1Lisa Horne 1 

Apex trigger not working during data loader upload.

I need to alter my trigger to run on Batch jobs as well as when they are updated one at a time.  Could someone help me do that?  This trigger creates a task when a lead is created and the Lead Web Comment field is filled out.



trigger CreateTaskOnLead on Lead (after insert) {
    List<Task> lTask = new List<Task>();
      Task t;
    
      if(Trigger.isAfter) {
        if(Trigger.isInsert) {
           for(Lead l: Trigger.new) {
              
               if((l.Lead_Web_Comment__c != null)){
                 t = new Task();
                 t.OwnerId = l.OwnerId;
                 t.Subject = 'Lead Web Comment';
                 t.Priority = 'Normal';
                 t.Status = 'Completed';
                 t.Type = 'Lead Web Comment';
                 t.Description = l.Lead_Web_Comment__c;
                 t.ActivityDate = Date.today();
                // t.CallDuration=0;
                 t.whoid=l.id;
                 lTask.add(t);  
               }
            }
            if(!lTask.IsEmpty())
                       insert t;
           }       
      }
}
Best Answer chosen by Lisa Horne 1
ShashForceShashForce
Hi Please change as below:

if(!lTask.IsEmpty())
                       insert lTask;
           }

All Answers

ShashForceShashForce
Hi Please change as below:

if(!lTask.IsEmpty())
                       insert lTask;
           }
This was selected as the best answer
Lisa Horne 1Lisa Horne 1
Thank you Shashank!