Apex Trigger Example using Map

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

No alt text provided for this image


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.

Lalit K.

7x Salesforce Certified Developer @ Extentia Information Technology

2 年

Beautiful article, I think soql should not be inside for loop

Sujitkumar Kadlag

Assistant Manager at GKN Aerospace with +10 yr's experience in Manufacturing

2 年

Well explained..

回复
Aarushi Garg

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 ?

要查看或添加评论,请登录

Sudhanshu Jain ?的更多文章

  • Exploring Exception Handling in Salesforce Apex: A Conversation Between Teacher and Student

    Exploring Exception Handling in Salesforce Apex: A Conversation Between Teacher and Student

    Teacher (T): Hey there, folks! Today, I'm having a chat with one of my eager students about a topic close to every…

  • Short Story : The Salesforce Developer's Dream

    Short Story : The Salesforce Developer's Dream

    Once upon a time, there was a college student named Jack who had always been fascinated by the world of technology. He…

  • Short Story : The Salesforce Interview

    Short Story : The Salesforce Interview

    John: Good morning, I'm here for my Salesforce developer interview. Interviewer: Good morning, John.

  • 10 tips for Salesforce Flow Experts

    10 tips for Salesforce Flow Experts

    Salesforce Flow is a powerful tool that allows you to automate repetitive tasks, gather and update information, send…

  • SOQL basics with example

    SOQL basics with example

    SOQL (Salesforce Object Query Language) is a query language used in Salesforce to retrieve data from one or more…

  • Basics of Apex Triggers

    Basics of Apex Triggers

    Apex Triggers in #Salesforce are a powerful tool that allow you to automate certain actions in the Salesforce platform.…

  • 10 ways to find a highly paid job in IT Industry in India

    10 ways to find a highly paid job in IT Industry in India

    Information Technology (IT) is one of the most in-demand fields in India, with a wide range of job opportunities…

  • SOAP API in Salesforce

    SOAP API in Salesforce

    SOAP API (Simple Object Access Protocol) is a protocol for accessing web services in Salesforce. It allows developers…

  • REST API in Salesforce

    REST API in Salesforce

    REST API (Representational State Transfer Application Programming Interface) is a popular way to access and manipulate…

  • My first Startup venture

    My first Startup venture

    "2000 rupees ! you are in final year now, you should learn the value of money" It's never easy to pitch your startup…

    2 条评论

社区洞察

其他会员也浏览了