Apex Trigger Example using Map
Sudhanshu Jain ?
I coach people to get highly paid for their skills | Educator | Business Consulting for EdTech, Coaches and Consultants | Technopreneur Acadmy | Career Coaching | Business Storytelling
Here's an example of an Apex Trigger that uses maps to avoid the deletion of Leave Request object, if its parent Consultant's status is Approved and Type is Employee
In this example, the trigger is associated with the Leave Request object and is set to run after the records which are getting deleted. It then checks if the Parent Consultant's status is Approved and Type is Employee, it shows an error.
Using maps in this way allows the trigger to efficiently access and update the related records, rather than querying for them multiple times. This can help to improve the performance of the trigger and prevent issues with governor limits.
7x Salesforce Certified Developer @ Extentia Information Technology
2 年Beautiful article, I think soql should not be inside for loop
Assistant Manager at GKN Aerospace with +10 yr's experience in Manufacturing
2 年Well explained..
8x Salesforce Certified | Solving Complex Problems | Simplifying Solutions
2 年What about bulkification( multiple accs updates ina single transaction) and is this query under for loop justified ? Sudhanshu Jain ?