You need to sign in to do that
Don't have an account?
Anu Raj.ax1269
How to get the Latest Task created on Lead
I am trying to get the latest task created on Lead from task object.
My scenario is that if there are 2 leads - Lead1 and Lead2. And both have 2 task created for it, Lead1 contain taska - (created date = today) taskb - (created date = yesterday). And for Lead2 contain taskc - (created date = today - 2) taskd - (created date = today - 4).
It should give result of all the latest created task in the lead1 and lead2 (Result - lead1 (taska) And Lead2(taskc)).
Please provide me the possible ways to do this scenario.
Maybe others have a better way, but personally I would use SOQL to find the latest task for each lead.
Try this:
accLst = [Select Id,Name,(Select Id,createdDate, Subject From Tasks order by CreatedDate Limit 1) From Account];
for(Account a: accLst)
{
for(Task t: accLst.Tasks)
{
tskLst.add(t);
}
}
Thanks
I guess on the above code you will need to change Account to Lead
same in the for statement