Write a trigger that updates the Account ‘Number of Opportunities’ field when an Opportunity is inserted, updated, or deleted.
This Apex trigger ensures that the custom field Number_of_Opportunities__c on the Account object always reflects the current number of related Opportunity records. It runs after insert, update, and delete operations on Opportunity. Trigger- Apex class-