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
michaellee.ampfmichaellee.ampf 

Adding an Audit Log

Hi,

 

I've got a VisualForce PDF page that I'd like to add some sort of audit trail on when the page is generated.

 

I've got an object created to store the data, and the code to insert the data I want to capture into the object, but it turns out that I'm not able to run DML within (say) the constructor of the controller to log that is being used.  Has anyone done this sort of audit trail before? If so, how did you do it? 

 

Thanks,

Michael

gtindugtindu

Add your audit log to a separate PageRefence function - and use the action tag of the page to call it

 

// Apex
public PageReference LogAuditData() {
  // insert new AuditInformation
}

// VisualForce
<page controller="myController" action="{!LogAuditData}">

</page>

 

 

michaellee.ampfmichaellee.ampf

This works, but I'm seeing two entries in the log each time I load a page instead of one.