• Peter Minetree
  • 0 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 1
Future methods are typically used for:
Callouts to external Web services. If you are making callouts from a trigger or after performing a DML operation, you must use a future or queueable method. A callout in a trigger would hold the database connection open for the lifetime of the callout and that is a "no-no" in a multitenant environment.
I'm trying to do the Understanding Execution Context module challenge and I really can't see why this won't work. The following code says
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountTrigger: execution of BeforeInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old Class.AccountTriggerHandler.CreateAccounts:

trigger AccountTrigger on Account (before insert) { 
     if ( Trigger.isBefore && Trigger.isInsert)

public class AccountTriggerHandler {
    public static void CreateAccounts(List<Account> Accnts)
         List<Account> ValidAccounts = new List<Account>();
            for (Account a : Accnts) {
               a.ShippingState = a.billingState;
            if (ValidAccounts.size() > 0) {
                insert ValidAccounts;