I trying to find a solution how to handle any metadata changes in Salesforce using Apex. At the moment my main goal handle changes in any ApexClass
record. I need to have the ability to understand that ApexClass
was updated and get ApexClass
Body in my future service method in moment upsert OR delete ApexClass
.
Do you have idea how I can do that?
Thanks in advance!
I tried use Trigger - Implement Trigger for ApexClass
is forbidden
We don't insert/upsert/delete classes, we deploy changes to them with Metadata API. I don't think you can hook any automation to that.
You could create a scheduled job that checks SetupAuditTrail or ApexClass/ApexTrigger or DeployResult tables. You could check Event Monitoring's documentation, there's something about Metadata events (but I think it'll be just a log after the fact, it won't emit a platform event the moment deployment occurs)
In a way you're solving it in wrong place. Ban everybody from deploying directly to production and hook something to your CI job (Circle CI, Github actions, gearset, azure devops, copado... what have you)