How to query view setup audit trail using apex in Salesforce?

How to query view setup audit trail using apex in Salesforce?

Starting with Winter’16 the SetupAuditTrail object is exposed to query from Apex.

For fields in the object, check the below link

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_setupaudittrail.htm

Sample SOQL:

List<SetupAuditTrail> listAudits = [SELECT Id, 
Action, 
CreatedBy.Name, 
CreatedDate, 
Display, 
Section 
FROM SetupAuditTrail 
WHERE CreatedBy.Email LIKE ‘%abc.com%’];

2 thoughts on “How to query view setup audit trail using apex in Salesforce?

  • SOQL on SetupAuditTrail is not returning Login As Information.
    When I am using impersonate (log in as) then it is creating a record in SetupAuditTrail but it is not coming as a result in SOQL.

    • DelegateUser column in SetupAuditTrail is the user who executed the action in Setup. If a Login-As user didn’t perform the action, this field is blank. This field is available in API version 35.0 and later.

Leave a Reply