Salesforce Apex Triggers 101

Gain the knowledge and experience to leverage Apex Triggers effectively.

Course Content

Expand All
Lesson Content
0% Complete 0/1 Steps

About Instructor

Luke Freeland

Luke is a 15 x certified Salesforce Architect and full-stack Developer who provides Salesforce technical consulting services out of his company, Metillium, Inc. He has been developing and creating custom Salesforce applications since 2011. He has done numerous custom applications using Visualforce, Apex, Triggers, Lightning Web Components (LWCs), Aura components, declarative tools and more. He also has done numerous integrations using the Salesforce APIs and other tools. He loves training others and skilling them up!

13 Courses

Not Enrolled
This course is currently closed49.99

Course Includes

  • 9 Lessons
  • 50 Topics
  • Course Certificate

Responses

  1. Hello Luke,

    I was trying to write a trigger that restricts if there exists a contact on Account, below is the code. This is giving me System.FinalException: SObject row does not allow errors.

    trigger AccountTrigger2 on Account (after insert, before delete) {
    if(trigger.isBefore && trigger.isDelete){
    List queryAccount = new List([SELECT Id, (SELECT id, Name FROM Contacts) FROM Account WHERE id IN : trigger.old]);
    System.debug(‘## queryAccount’ +queryAccount);
    for(Account deleteAccount : queryAccount){
    if(!deleteAccount.Contacts.isEmpty()){
    deleteAccount.addError(‘Accounts with Opportunities cannot be deleted’);
    }
    }
    }
    }

    Can you please help me here??

    1. Hey Navya,

      addError can be used on the records from Trigger.old or Trigger.New. addError can’t be used on records that were queried. The for loop is iterating on the records that were queried and stored in the queryAccount List.

      Hint: The queried records can be put into a Map and then used in a for loop later….