Skip to content

Instantly share code, notes, and snippets.

@kamalpreet-rad
Created December 7, 2023 00:48
Show Gist options
  • Save kamalpreet-rad/ec7b93e7e1103f5645a9b1edf493f2d1 to your computer and use it in GitHub Desktop.
Save kamalpreet-rad/ec7b93e7e1103f5645a9b1edf493f2d1 to your computer and use it in GitHub Desktop.
Week 3
trigger LeadTrigger on Lead (after insert, after update)
{
if(Trigger.isAfter)
{
if(trigger.isInsert)
{
LeadHandlerClass.CreateTask(Trigger.New,Null);
}
if(Trigger.isUpdate)
{
LeadHandlerClass.CreateTask(Trigger.New,Trigger.oldMap);
}
}
}
public class LeadHandlerClass
{
Public Static Void CreateTask(List<Lead> Listofleads, Map <Id, Lead> OldLeadMap)
{
List<Task> newlistoftasks = new List<Task>();
for(Lead ld : Listofleads)
{
if( ld.ProductInterest__c !=null && (OldLeadMap == null || ld.ProductInterest__c != OldLeadMap.get(ld.id).ProductInterest__c))
{
Task t = new Task();
t.Subject = 'Follow With New Lead';
t.Status = 'Not Started';
t.WhoId = ld.Id;
newlistoftasks.add(t);
}
If(!newlistoftasks.isEmpty())
{
insert newlistoftasks;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment