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
FCommFComm 

How to get last activity date of an Account's Open activity

Any ideas on How to get last activity date of an Account's Open activity?

 

Thanks.

ExecbizExecbiz

The way I've done similar actions is to create an Event trigger (after insert, after update) that updates a custom field in my Account record (Last_Activity_Date__c) if the Last Activity field is null or if the event date is later than the date in the Last Activity field.

 

This obviously won't do much for events that have already been logged, but as you start logging more activity, more and more Accounts will start populating the Last Activity Date 

CRM indiaCRM india

Hi

 

Can you share the code, since I have similar requirement in past.

 

Thanks

Amit

ExecbizExecbiz

Sure thing...here is a very similar example from my org:

 

 

trigger UpdatePresDate on Event (after insert, after update){

 

Event event = Trigger.new[0];

Opportunity opp = new Opportunity();

 

if(event.Type == 'Presentation'){

for(Opportunity o:[Select Id, Presentation_Date__c from Opportunity where

Id = :event.whatId limit 1]){

opp = o;

 

if(event.ActivityDate < opp.Presentation_Date__c || opp.Presentation_Date__c == null)

opp.Presentation_Date__c = event.ActivityDate;

 

update opp;

}

}

}

 

The field on my opportunity is Presentation_Date__c.  It is filled by the trigger on the Event update, if the event type is Presentation, and if the presentation date is before the existing Presentation_Date__c (since I have mulitple presentations, I want the earliest presentation date to be passed) OR if Presentation_Date__c is null.  This could easily be changed to updating an account field using the whoId event field to obtain the related Contact, then querying to get the contact's account. 

 

 

Message Edited by Execbiz on 08-06-2009 07:50 AM