+ Start a Discussion

Last Activity Date By Profile

I am looking for some help on populating a last activity date field.  I know that SF already records a last activity but we have several buisness lines that deal with one customer and we need a last activity date for each business line.  I know this will require a trigger to find the last activity by the assigned owners profile but I am not sure where to even start.  Any help would be appreciated.  Thank you.

Ritesh AswaneyRitesh Aswaney

You first need to thrash out the design approach - so whether you'd like to add multiple date time fields on your record, one per profile


whether you'd like a linked object which holds a bundle of Last Updated FIelds, one per profile, which is either Master/Detail or looks up to the object you're tracking.


You'd need a before / after update trigger depending on the design approach you go with , and then based on the Profile of the User stamp the value into the relevant field.


UserInfo.getProfileId() will give you the Profile Id of the running user.


An extreme config approach would be to hold the Profile -> FIeld translation in a CUstom Setting and then use Dynamic Apex to set the values.

eg List Custom Setting : ProfileLastUpdated

Fields : ProfileId, ProfileName, LastUpdatedField

Values : 001....,   System....., SysAdminLastUpdated__c


You could then get the relevant field using an inexpensive Custom Setting lookup

Account acc;

String fieldNameForUser =  ProfileLastUpdated__c.getInstance(UserInfo.getProfileId());

acc.put(fieldNameForUser, Datetime.now());