Write bulk-safe Apex triggers to maintain two custom count fields on Account: Contact_Count__c and Opportunity_Count__c. The Contact trigger must recalculate the Contact count after insert, update, delete, and undelete. The Opportunity trigger must recalculate the Opportunity count after insert, update, delete, and undelete. Handle records reassigned to another Account and reset counts to zero when the last child is removed. Use aggregate SOQL and avoid queries or DML inside loops.
Contact_Count__c and Opportunity_Count__c as Number fields on Account.