+ Start a Discussion
Bharat.SharmaBharat.Sharma 

Show Event Details in Lead Page.

Hello All,

I have a query regarding Apex please help me out,
I would like to show some details of event in Lead page ((Like meeting Status - Custom Field ) API name - Meeting_Status__c) 
this not the only one i want to show some Checkbox Is that possible to apex Trigger or should I use Apex Class.??
Please provide me a proper Solution or Reference.

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) {
                
            }
            
        }
    }
}

 
SandhyaSandhya (Salesforce Developers) 
Hi,

This can be achieved through trigger please refer below sample code.
 
trigger ExampleTrigger on Task (after insert) {

    set<Id> leadIds = new  set<Id>();
    for(Task t: trigger.new){
        if(t.Who.Type == 'Lead'){
            leadIds.add(t.WhoId);
        }
    }
    list<Lead> leadsToUpdate = new list<Lead>([Select Id, Name, Last_Activity_Type, (Select Id, ActivityDate, Type__c From Tasks) From Lead Where Id in : leadIds]);

    //This will cycyle through all the leads
    for(Lead l: leadsToUpdate){
        Date latestActivity;

            /*This will go through each task related to the current lead and find the 
            task with the latest date, and change the Last_Activity_Date__c fieild
            on that lead to the type of that latest activity*/

            for(Task t : l.Tasks){
            if (latestActivity == null || lastestActivity < t.ActivityDate){
                latestActivity = t.ActivityDate;
                l.Last_Activity_Type__c = t.Type__c;
            }
        }
    }

    update leadsToUpdate;

}

Please refer below link for the same.

http://salesforce.stackexchange.com/questions/16743/determine-activity-type-completed-on-lead-object
 
Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution. 
 
Thanks and Regards
Sandhya

 
Bharat.SharmaBharat.Sharma
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