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
frank2anilfrank2anil 

How to make it as bulk trigger

Hi guys,

 

can anyone help me how to make this trigger as bulk trigger.

 

trigger upcom on Finance__c (after insert,after update) {
    
    Finance__c f;
    
    for(Finance__c fs:trigger.new){
    f=fs;
    }
    if(f.Opportunity__c!=null){
   // opportunity op=[select id,name from opportunity where id=:
    for(Comments__c cm:[select id,opportunity__c,Finance__c from Comments__c where Opportunity__c=:f.opportunity__c limit 1]){
    cm.finance__c=f.id;
    update cm;
    }
    }

}

 

Thanks

Frank

Best Answer chosen by Admin (Salesforce Developers) 
HariDineshHariDinesh

Hi,

 

Please find the Bulk Trigger 

 

trigger upcom on Finance__c (after insert,after update) 
{
    List<Finance__c>  flist = new List<Finance__c>();
    for(Finance__c fs:trigger.new)
	{
	   if(fs.Opportunity__c!=null)
          flist.add(fs);
	 }
    
	list<Comments__c> comlist = [select id,opportunity__c,Finance__c from Comments__c];
	list<Comments__c> updatedcomlist = new list<Comments__c>();
	for(Finance__c fss : flist)
	{
	  for(Comments__c cm: comlist)
	  {
       if(cm.Opportunity__c == fss.opportunity__c )
	     cm.finance__c=f.id;
         updatedcomlist.add(cm);
	    }
	
    
    }
	
	upsert updatedcomlist;

}

 

This trigger will work as Bulk trigger.

If any changes are required with respect to functionality modify it accordingly and use the trigger

All Answers

HariDineshHariDinesh

Hi,

 

Please find the Bulk Trigger 

 

trigger upcom on Finance__c (after insert,after update) 
{
    List<Finance__c>  flist = new List<Finance__c>();
    for(Finance__c fs:trigger.new)
	{
	   if(fs.Opportunity__c!=null)
          flist.add(fs);
	 }
    
	list<Comments__c> comlist = [select id,opportunity__c,Finance__c from Comments__c];
	list<Comments__c> updatedcomlist = new list<Comments__c>();
	for(Finance__c fss : flist)
	{
	  for(Comments__c cm: comlist)
	  {
       if(cm.Opportunity__c == fss.opportunity__c )
	     cm.finance__c=f.id;
         updatedcomlist.add(cm);
	    }
	
    
    }
	
	upsert updatedcomlist;

}

 

This trigger will work as Bulk trigger.

If any changes are required with respect to functionality modify it accordingly and use the trigger

This was selected as the best answer
frank2anilfrank2anil

Hi Haridinesh

 

Thanks u a lot for the help!

 

Thanks

Frank.