• Parikshit Sarkar 14
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
An environment has two Apex Triggers: an after-update trigger on Account and an after-update trigger on Contact. The Account after-update trigger fires whenever an Account’s address is updated, and it updates every associated Contact with that address. The Contact after-update trigger fires on every edit, and it updates every Campaign Member record related to the Contact with the Contact’s state.
Consider the following: A mass update of 200 Account records’ addresses, where each Account has 50 Contacts. Each Contact has 1 Campaign Member. This means there are 10,000 Contact records across the Accounts and 10,000 Campaign Member records across the contacts.
What will happen when the mass update occurs?


A. The mass update will fail, since the two triggers fire in the same context, thus exceeding the number of records processed by DML statements.
B. There will be no error, since each trigger fires within its own context and each trigger does not exceed the limit of the number of records processed by DML statements.
C. There will be no error, since the limit on the number of records processed by DML statements is 50,000.
D. The mass update of Account address will succeed, but the Contact address updates will fail due to exceeding number of records processed by DML statements.



I think the answer is A but it is given as B. I am not 100% sure. Can someone please explain and confirm. 

Thanks .
A custom field Exec_Count_c of type Number is created on an Account object. An account record with value of "1" for a: Exec_Count_c is saved.

A workflow field update is defined on the Exec_Count_c field, to increment its value every time an account record is created or updated. The following trigger is defined on the account:

trigger ExecOrderTrigger on Account (before insert, before update, after insert, after update){ for (Account accountInstance: Trigger.New){ if (Trigger . isBefore) { accountInstance Exec_Count_c += 1; } System. debug (accountInstance.Exec_Count_c); } }
A custom field Exec_Count_c of type Number is created on an Account object. An account record with value of "1" for a: Exec_Count_c is saved.

A workflow field update is defined on the Exec_Count_c field, to increment its value every time an account record is created or updated. The following trigger is defined on the account:

trigger ExecOrderTrigger on Account (before insert, before update, after insert, after update){ for (Account accountInstance: Trigger.New){ if (Trigger . isBefore) { accountInstance Exec_Count_c += 1; } System. debug (accountInstance.Exec_Count_c); } }
global class LeadProcessor implements 
    Database.Batchable<Leads>, Database.Stateful {
//     Database.Batchable<Sobject>, Database.Stateful {

    
    // instance member to retain state across transactions
    global Integer recordsProcessed = 0;

    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([Select LastName From Leads ]);

     }
          
    }

    global void execute(Database.BatchableContext bc, List<Leads> scope){
        // process each batch of records
        List<Leads> leads = new List<Leads>();
            for (Leads:leads) {
                Leads.LeadSource = Dreamforce;
                // add Leads to the list to be updated
                leads.add(leads);
                // increment the instance member counter
                recordsProcessed = recordsProcessed + 1;
            }
        }
        update leads;
    }    

    global void finish(Database.BatchableContext bc){
        System.debug(recordsProcessed + ' records processed. Shazam!');
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
            JobItemsProcessed,
            TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :bc.getJobId()];
        // call some utility to send email
        EmailUtils.sendMessage(a, recordsProcessed);
    }    

}