Last active
April 13, 2023 12:03
-
-
Save asmitakhare/c4ad100edf866c0c96ac4b9879addc93 to your computer and use it in GitHub Desktop.
WeekTwoHomeworkRad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class WeekThreeHomeworkHandler { | |
//it is public static condition and not returning anything | |
public static void leadHandler(List<Lead> lstLeads) { | |
List<Task> listTask = new List<Task>(); // intiating a task list | |
//writing an if condition where it will create a new task when productInterest picklist has one of the values | |
//if(l.ProductInterest__c == 'Cookbook Authorship' | |
//|| l.ProductInterest__c =='Cookbook Editing' | |
//||l. ProductInterest__c =='Cookbook Distribution') | |
for (Lead l : lstLeads) { | |
if (l.ProductInterest__c != null) { | |
Task task = new Task(); | |
task.subject = 'New Task' + l.ProductInterest__c; //assigning subject name as | |
task.whoId = l.OwnerId; | |
task.Status = 'Not Started'; | |
task.priority = 'Normal'; | |
listTask.add(task); | |
} | |
} | |
insert listTask; | |
} | |
public static void leadHandlerUpdate(List<Lead> newLeads, Map<Id, Lead>oldLeads){ | |
List<Task> tasksToCreate = new List<Task>(); | |
for (Lead newLead : newLeads) { | |
Lead oldLead = oldLeadsMap.get(newLead.Id); | |
if (newLead.Product_Interest__c != null && | |
(oldLead == null || newLead.Product_Interest__c != oldLead.Product_Interest__c)) { | |
Task tasks = new Task(); | |
tasks.Subject = 'New Task' + l.ProductInterest__c; | |
tasks.Priority = 'Normal'; | |
tasks.Status = 'Not Started'; | |
tasks.WhoId = newLead.Id; | |
tasksToCreate.add(tasks); | |
} | |
} | |
insert tasksToCreate; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment