How to Master Apex Triggers? Apex Trigger Scenarios

on

|

views

and

comments

Dear #Trailblazers,

Here is the Link to Many Apex Trigger Scenarios that you can practice and get more and more strong into Apex Trigger.

https://docs.google.com/spreadsheets/d/e/2PACX-1vTuWxvvEdeu1TIBrla8cD9-jiMaWUEJbylenZN4gU7qtEp-pbF2vCKfTDRdGce9e9pJdLG3GiYDTnJYH15vCkc/pubhtml

Thanks & Happy Coding

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

5 COMMENTS

  1. Solution for Row#3

    // Write a trigger on contact to prevent duplicate records based on Contact Email & Contact Phone.

    // Asumption: Only on insert context, if you want to consider the update case then check if any of the values have changed between oldMap and new list

    trigger ContactTrigger on Contact(before insert){

    Set<String> setEmailPhoneKeys = new Set<String>();
    Set<String> setEmails = new Set<String>();
    Set<String> setPhones = new Set<String>();

    for(Contact objContact : Trigger.new){
    if(objContact.Email != null && objContact.Phone != null){
    setEmails.add(objContact.Email);
    setPhones.add(objContact.Phone);
    }
    }

    for(Contact objContact : [SELECT Phone, Email from Contact WHERE Phone IN : setPhones AND Email IN : setEmails]){
    setEmailPhoneKeys.add(objContact.Email + '-' + objContact.Phone);
    }

    for(Contact objContact : Trigger.new){
    if(objContact.Email != null && objContact.Phone != null){
    String key = objContact.Email + '-' + objContact.Phone;
    if(setEmailPhoneKeys.contains(key)){
    objContact.addError('Duplicate contact exists!');
    }
    }
    }

    }

  2. Solution Row#4

    // Write a trigger, only system admin user should be able to delete the task.

    trigger TaskTrigger on Task(before delete){

    Id profileId = UserInfo.getProfileId();
    String profileName = [SELECT Name from Profile WHERE ID =: profileId].Name;

    for(Task objTask : trigger.old){
    if(profileName != 'System Administrator'){
    objTask.addError('Not System admin');
    }
    }

    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential