Posts

Apex Triggers - 16 (TCS Interview Question)

  1. Scenario Overview This automation addresses a TCS Interview Question involving roll-up style calculation across parent-child relationships. The Account object contains a custom text field named Max_OPP__c . The requirement mandates that this field must always display the Name of the related Opportunity record that has the highest Amount . Because this value can change across any data mutation phase, the trigger handles a full suite of events ( after insert , after update , after delete , and after undelete ) to safely re-calculate metrics on parent Accounts. or Update the Parent Account field with the Opportunity Name that has the Highest Amount. 2. Apex Handler Class java public class OpportunityTriggerHandler { public static void updateMaxOpportunityName ( List < Opportunity > newOpps , Map < Id , Opportunity > oldOppMap ) { Set < Id > accountIds = new Set < Id >(); // Phase 1: Track all impacted Account IDs acros...

Apex Triggers - 17 (Deloitte Interview Question)

  1. Scenario Overview This automation solves a Deloitte Interview Question focused on enforcing data integrity across parent-child relationships . The contact object features a custom checkbox field, Primary_Contact__c . The requirement mandates that each Account can have at most one primary contact . If a user tries to create or update a contact to be a duplicate primary contact under the same account—or re-parents an existing primary contact to an account that already contains one—the transaction must block and throw an error .  Because data validation must block execution before commit phases, these criteria execute entirely in before insert and before update context steps . or Enforce a single Primary Contact on an Account. 2. Apex Handler Class java public class ContactTriggerHandler { public static void preventDuplicatePrimaryContacts ( List < Contact > newContacts , Map < Id , Contact > oldContactMap ) { Set < Id > accountIds...