+ Start a Discussion

Adding an Audit Log



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? 





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}">





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