You need to sign in to do that
Don't have an account?
kondru sampreeth
when lead status changed to"closed-but not converted" then task should be assign to a manager
when lead status changed to"closed-but not converted" then task should be assign to a manager ,
please write a triiger how it will do?
please write a triiger how it will do?
1. Create a after update trigger on Lead object
2. Then check lead status is 'closed-but not converted' and old value of status is not 'closed-but not converted'
3. Then store all the lead id in list varibale
4. Using that list variable query all the task records in the system (non closed task)
5. Then then update all task owner into Manager user [ You need to query the user record and check the manager as per your logic and assign into owner id of task]
To get start with apex code, check the Salesforce trailhead module https://developer.salesforce.com/trailhead/trail/force_com_programmatic_beginner
trigger triggerForLeadStatuswithTask on Lead (After Insert) {
Set<Id>objSet = new Set<Id> ();
for(Lead objLead : Trigger.New) {
if(objLead.Status == 'Closed' && objLead.IsConverted == False) {
objSet.add(objLead.Id);
}
}
objSet.remove(null);
List<Task>lstTask = new List<Task> ();
if(!objSet.isEmpty()) {
for(Lead itrLead : [SELECT Id,Name FROM Lead WHERE Id IN : objSet LIMIT 10000]) {
for(User objUser : [SELECT Id,UserRoleId FROM User WHERE UserRole.Name='Manager' LIMIT 10000]) {
Task objTask = new Task ();
objTask.WhoId = itrLead.Id;
objTask.OwnerId = objUser.Id;
objTask.Subject = 'Other';
lstTask.add(objTask);
}
}
}
if(!lstTask.isEmpty ()) {
insert lstTask;
}
}
If you are stisfied with this, please comment.
Thanks