+ Start a Discussion
Srinu@dreamsSrinu@dreams 

I have 1000 records, how can I execute 200 records each time in Trigger?

Best Answer chosen by Admin (Salesforce Developers) 
Gunners_23Gunners_23

By default triggers will run in a batch of 200 records. For 200 record one trigger invocation, even in case of Bulk API.

 

Consider a scenario where you're inserting 1100 records then it will be run in 6 batches

 

200 * 5  + 100 * 1 = 6 (Invocations)

All Answers

stcforcestcforce

if you perform a large operation, the trigger should receive a subset of records (up to 200). I'm not sure whether this can be fixed to be 200.

asish1989asish1989

Hi

     Try in this way..It  may  will help you .

             trigger opportunityLimitExample on Account(after delete, after insert, after update) {

                     List<Opportunity> opptys = [select id, description, name, accountid,  closedate, stagename from Opportunity where accountId IN :Trigger.newMap.keySet()];

        if(opptys  !=NULL && opptys.size() != NULL ){

          // write a condition about functionality of Trigger ..to track on how many records are not updated..

              for(Integer i =0; i<200; i++){

                  //write logic

             }

              //write update or insert statement..

         }

}

 

did this post solve your issue..if so please mark it solved..

 

thanks

asish

           

Gunners_23Gunners_23

By default triggers will run in a batch of 200 records. For 200 record one trigger invocation, even in case of Bulk API.

 

Consider a scenario where you're inserting 1100 records then it will be run in 6 batches

 

200 * 5  + 100 * 1 = 6 (Invocations)

This was selected as the best answer
KaranrajKaranraj

Use SOQL for loops to operate on records in batches of 200.

SOQL for loop, which iterates over the returned results in batches of 200 records. This reduces the size of the ml list variable which now holds 200 items instead of all items in the query results, and gets recreated for every batch.


for (List<Merchandise__c> ml : [SELECT Id,Name FROM Merchandise__c])

{
// Do something.
}

 

You can also batch apex class to process large number of records