+ Start a Discussion
amateur1amateur1 

bulkification of trigger

hi 

 

this is the trigger i have written please help me how to bulkify this trigger

 

 

trigger UpdateTenantAllocation on Tenant_Allocations__c (after update)
 {
 public list<Invoice_and_Billing_Detail__c> INVBD {get;set;}
INVBD  = new List<Invoice_and_Billing_Detail__c>();
for(Tenant_Allocations__c t:trigger.new)
{
Location__c  l1=[select id,Bill_Tenants__c from location__c where id=:t.Location_new__c];
system.debug('............'+l1);
Invoice_and_Billing_Detail__c[] lb=[select id,Rate__c, name,Location1__c from Invoice_and_Billing_Detail__c where Location1__c=:l1.id and QB_Txn_ID__c=null ]; 
system.debug('............'+lb);
for(Invoice_and_Billing_Detail__c lb1:lb){
if(l1.Bill_Tenants__c==true)
{
lb1.Rate__c=t.Next_Period_Invoice_Amount__c;
}
else 
{
lb1.Rate__c=222;
}
 INVBD.add(lb1);
}
update  INVBD;
system.debug('............'+lb);
}
}
AdrianCCAdrianCC

What's the relationship between Tenant_Allocations__c, location__c  and Invoice_and_Billing_Detail__c? Lookups of Master-Detail?

Are all of them one-to-one? Like for 1 Location you have only 1 Tenant Allocation and only 1 Invoice Detail.