Trigger on ApexClass Object

I want to try to log changes on apex classes in my org. Everytime the apex class is edited by someone i want to log the username and timestamp. Sounds easy but as i tried to write a simple trigger on the ApexClass object i got an error:

Error: Compile Error: SObject type does not allow triggers: ApexClass

This is what i’ve tried so far without any luck:

trigger myTrigger on ApexClass(after update) {

Is there any workaround for this approach?


Triggers are not allowed on Apex classes. I think the solution here is a behavioral and process one and not a trigger. In my opinion, all code should be kept in some version control system. Changes should be committed, tested and reviewed prior to deploying to production. The advantage of a VCS is the ability to track changes and rollback as needed.

Source : Link , Question Author : Sergej Utko , Answer Author : greenstork

Leave a Comment