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
Luciano StragaLuciano Straga 

Catch record last access within a trigger

Hi folks, I'm trying to catch the 'event' of a record, when this record was seen. 

Basically, I have a VisualForce that creates a record, and I want to UPDATE a field when this record is viewed /accessed for the first time.

I tried this:

trigger CaseTrigger on Trigger (before update) {
    for(Case ca : trigger.new){
        if(ca.CreatedDate != ca.LastViewedDate){
            // FIELD UPDATE
        }
    }  
}


The problem is that the 'LastViewedDate' field is updated but the trigger is not get activated for this event. Apparently, this standard date fields are not consider by the trigger execution. Might be?


As a workaround, I thought by developing a visicualforce and enbedded it in the record layout and work it there, but is more complex.


Thanks in advance!
Andy BoettcherAndy Boettcher
Stock Salesforce triggers are only on the DML actions - to catch a "view", your best bet would be to make a simple VF page with an apex:detail tag inside of it to render the regular Page Layout.  In the apex:page tag, you can do the "action" attribute to track the view.