function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
srikanth11srikanth11 

trigger issue

can some one please tell me what exactly is bulkification of trigger

Devendra NataniDevendra Natani

Hi,

 

The term bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time. When a batch of records initiate Apex, a single instance of that Apex code is executed, but it needs to handle all of the records in that given batch. For example, a trigger could be invoked by an Force.com Web Services API call that inserted a batch of records. Or a custom Apex Web Service. So if a batch of records invokes the the same Apex code, all of those records need to be processed as a bulk, in order to write scalable code and avoid hitting governor limits.

 

Please refer the following url for more details. 

http://wiki.developerforce.com/page/Best_Practice:_Bulkify_Your_Code

 

 

Shashikant SharmaShashikant Sharma

Bulk Trigger means no Governor Limits are hit while executing trigger on bulk data actions. Like bulk insert, bulk update or bulk delete.

 

Please see this for Example : http://forceschool.blogspot.com/2011/05/writing-apex-trigger-save-limits-in.html

srikanth11srikanth11

the website u seegested is usefull but at this point its a bit difficult to understand the scenario so could you plz tell me how to bulkify this trigger

 

trigger updatefundtotal on opportunity( after insert,after update) {
    //Integer i = 0;
    //Set<ID> fundIds = new Set<ID>();
   
    Decimal id2num =0.0;
  
  
 
    //taking all the  opportunities 
    
    opportunity o = Trigger.new[0];
    
   
    //retrieving funds where id equals to opportunity fund
    
         fund__c[] fn =[select ID,Name,Current_AUM__c,Checkbox_Fire__c from fund__c where ID =:o.fund__c ];
         
          for(fund__c fn1:fn)
          {
         
           opportunity[] opp=[select ID,Name,amount,Fund__r.Current_AUM__c from opportunity where fund__c=:fn1.ID  and stagename='booked'];

         
              
             
      //adding the remaining amounts of opportunity after deletion of a opportunity  and updating it to Current_AUM__c in fund    
for(opportunity opp1:opp)
          {
         
         id2num  =opp1.amount + id2num;
          fn1.Current_AUM__c = id2num ;        
                  
        }   
          }   update fn;
            
       
       
      }