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

Show event custom field in Lead detail page

Hello everyone 

I want to update event custom field in lead detail page please help me.
Ques: I have a three custom field in Event object
1- Meeting Status (API - Meeting_Status__c(picklist)) (values: Scheduled, Rescheduled, Cancelled, No Show)
2- Is Meeting Completed-( API-Is_Meeting_Completed__c(Checkbox))
3-First Meeting Scheduled-
(API - First_Meeting_Scheduled__c(Checkbox))

same as in Lead object 
I want that when any Event  create with the values of these three custom object or two custom field, lead  detail page would update them with same values.  
Crux of the matter is that i want to update Event custom field in Lead detail page.
 
See the Scenario...
 For more Details
 Please Help me And reply  ASAP.

Thanks and Regards
Bharat Sharma



 
Ankit SehgalAnkit Sehgal
You need to write a trigger on event for that
Bharat.SharmaBharat.Sharma
Thank you ! Ankit  for such a fast reply :) but i have already write but it isn't working..
trigger Evnt_meeting_update on Event (after delete, after insert,  after update) {

set<Id> leadIds = new  set<Id>();
    
    for(Event E: trigger.new){
  		
        if(E.Who.Type == 'Lead'){	
     		
            leadIds.add(E.WhoId);
		}
    }
    list<Lead> leadsToUpdate = new list<Lead>([Select Id, Meeting_Status__c, (Select Id, Meeting_Status__c,ActivityDate From Events) From Lead Where Id in : leadIds]);
	
    for(Lead l: leadsToUpdate){
        Date latestActivity;
    
    for(Event E : l.Events){
        
        if (latestActivity == null || lastestActivity < t.ActivityDate){
            latestActivity = t.ActivityDate;
            l.Meeting_Status__c = E.Meeting_Status__c;
        }
    }
 }
    
    Update leadsToUpdate;
}
Please help me Ankit.

 
Ankit SehgalAnkit Sehgal
Make a new Class CheckRecursive with the following code:
 
public Class checkRecursive
{
private static boolean run = true;
public static boolean runOnce()
{
    if(run)
    {
        run=false;
        return true;
    }
    else
    {
        return run;
    }
}
}


and edit your trigger like this:
 
trigger Evnt_meeting_update on Event (after delete, after insert,  after update)
{
   if(checkRecursive.runOnce())
   {
set<Id> leadIds = new  set<Id>();
    
    for(Event E: trigger.new){
  		
        if(E.Who.Type == 'Lead'){	
     		
            leadIds.add(E.WhoId);
		}
    }
    list<Lead> leadsToUpdate = new list<Lead>([Select Id, Meeting_Status__c, (Select Id, Meeting_Status__c,ActivityDate From Events) From Lead Where Id in : leadIds]);
	
    for(Lead l: leadsToUpdate){
        Date latestActivity;
    
    for(Event E : l.Events){
        
        if (latestActivity == null || lastestActivity < t.ActivityDate){
            latestActivity = t.ActivityDate;
            l.Meeting_Status__c = E.Meeting_Status__c;
        }
    }
      Update leadsToUpdate;
 }
}

The trigger looks fine but it is running recursively after each update. If this won't work then we would have to change the trigger code
Bharat.SharmaBharat.Sharma
Thank you ankit but there is some error like 
Variable does not exist: t.ActivityDate
 
Bharat.SharmaBharat.Sharma
Hello Ankit , i think we need to change the trigger code.
Can you please do it for me.because i havn't any idea that how can we write the same code alternativly.

Thank you !  
Kevin CrossKevin Cross
It looks like the references to t.ActivityDate should be E.ActivityDate just based on context of code and apparent logic.  I believe you are trying to check the activity date of each event to find the latest one then set meeting status for the Lead based on that.  If I am correct, the only two objects in the mix are "l" for Lead and "E" for Event.  I hope that makes sense.