Create Task for Lead Owner on Lead Creation

This trigger generates a follow-up Task for the Lead Owner when a new Lead record is created. It ensures timely engagement with prospects and automates task assignments.

Explore similar examples in this YouTube playlist.

Solution:

public class LeadTriggerHandler {

     public static void handleActivitiesAfterInsert (List<Lead> leadRecords) {

           List<Task> taskListToInsert = new List<Task>();

           for (Lead leadRec : leadRecords) {

                  Task taskRecord = new Task();

                  taskRecord.Priority = ‘High’;

                  taskRecord.OwnerId = leadRec.OwnerId;

                  taskRecord.Description = ‘Follow up with the new lead’;

                  taskRecord.Status = ‘Not Started’;

                  taskRecord.Subject = ‘Follow Up’;

                  taskRecord.WhoId = leadRec.Id;

                  taskListToInsert.add(taskRecord);

            }

            if(!taskListToInsert.isEmpty()) {

                   insert taskListToInsert;

             }

        }

 }

Want to Apply As Content Writer?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)