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
rashi krishanrashi krishan 

Update a field Last modified by on lead when its related list is updated

I need a trigger which updates a field name Last modified by on lead when any of its related list is created or updated
Vishal Negandhi 16Vishal Negandhi 16
So in this case, you'll need a trigger on all the related objects. 

However, LastModifiedBy is a field which cannot be updated. It automatically gets updated when any modification is performed. 
So all you can do is perform an update on Lead when any of the related records are updated (using a trigger). 

a rough sample for Campaign Member related list on Leads:
 
trigger updateLead on CampaignMember(after Insert){
    Set<Id> LeadIds = new Set<Id>(); 
    for(CampaignMember cm : trigger.new){
          if(cm.LeadId != null)
               LeadIds.add(cm.LeadId);
          }
     }    
     
     List<Lead> lstLeadsToUpdate = [Select Id From Lead WHERE Id IN :LeadIds];
     if(!lstLeadsToUpdate.isEmpty())
           update lstLeadsToUpdate;
​}

Since you're updating leads, the lastmodifiedby and the lastmodifieddate fields will be updated. 

Hope this helps :)