function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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;
        if(updateLeads.size()>0) {
                update updateLeads;
            catch (Exception e) {

SandhyaSandhya (Salesforce Developers) 

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:{
        if(t.Who.Type == 'Lead'){
    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.
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

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