I have Already implement this scenario please have a look.
public with sharing class Event_field_on_lead {
public static String ldPrefix = Lead.sObjectType.getDescribe().getKeyPrefix();
public static void updateEvent_field_on_lead(Set<ID> leadIds){
//Query all Leads and task-event child relationships//
List<Lead> Leads = [SELECT Id, LastActivityDate,
(SELECT Id, WhoId, Meeting_Status__c, ActivityDate FROM Events )
FROM Lead WHERE ID IN :leadIds];
List<Lead> updateLeads = new List<Lead>();
for (Lead l : Leads) {
Integer count = l.Events.size();
if (count != 0) {
for (Event e : l.Events){
if (l.LastActivityDate <= e.ActivityDate) {
l.Meeting__c = e.Meeting_Status__c;
}
}
}
updateLeads.add(l);
}
if(updateLeads.size()>0) {
try{
update updateLeads;
}
catch (Exception e) {
}
}
}
}
can you tell me what is latestActivity in this code ??and Sorry sandhya it is not working, there is some error like Variable does not exist:t.ActivityDate Variable does not exist: latestActivity Please assist me ..Thanks And Regards Bharat Sharma