function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sucharitha shekarsucharitha shekar 

Hi, how to write trigger to create two tasks when ever lead is created..

I would like to write a trigger  to create two tasks when ever lead is created....

Arunkumar RArunkumar R

Please try the below code and update code if you need any additional conditions,
trigger LeadTrigger on Lead (after insert) {

    if(Trigger.isAfter && Trigger.isInsert){
        List<Task> taskList = new List<Task>();
        for(Lead currLead : Trigger.New){
            Task newTask = new Task();
            newTask.WhoId= currLead.Id;
            newTask.ActivityDate =;
            newTask.Subject = 'test subject';
            newTask.Priority = 'Low';
            newTask.Status = 'Not Started';
        if(taskList.size() > 0){
            insert taskList;

Please do not post your requirements here. Instead, try to do something and ask your doubts here.
Vinod ChoudharyVinod Choudhary
Hi Ssucharitha,

The trigger should be like below.  you need to make changes in this whatever you wish to do.
trigger InsertCompletedCallTask on CampaignMember (after insert) {
list<Task> AddTask=new List<Task>();
	for(CampaignMember CM : {
		// Put Conditions Here whatever you want to check befor 
		if(cm.create_completed_call_task__c == true){
			AddTask.add(new Task(
			WhoId = CM.ContactId,
			Description = CM.Call_Notes__c,
			ActivityDate = CM.Call_Date__c,
			Status = 'Completed',
			Subject = 'Call - ' + CM.Call_Result__c, 
			Related_Campaign_ID__c = CM.CampaignId));
insert AddTask;

It will create Two task.

Hope this helps.

Hi , 

Please check the code below.
 User-added image