You need to sign in to do that
Don't have an account?

Bulkification of below code
trigger UpdateInvoiceBillingDetails on Can__c (before update,after update)
{
//BEFORE UPDATE FOR CAPTURING THE PREVIOUS INFORMATION TO RELATED CUSTOM FIELDS.
if(trigger.isbefore)
{
for(can__c c1:trigger.old)
{
for(Can__c c:trigger.new)
{
try{
Invoice_and_Billing_Detail__c lb=[select id,Service_Description__c,Start_Date__c,Stop_Date__c
from Invoice_and_Billing_Detail__c where id=:c.Last_Invoice_Detail__c];
system.debug('detailll'+lb);
Invoice_and_Billing_Header__c lh=[select id,QB_Invoice_Txn_ID__c from Invoice_and_Billing_Header__c where id=:c.Last_Invoice_Number__c];
//system.debug('header'+lh);
//EXECUTE ON EFFECTIVE DATE OF OLD RECORD AND THE NEW RECORD ARE NOT SAME AND
//THE FIELD QB INVOICE TXN ID SHOULD BE EMPTY IN INVOICE BILLING HEADER.
if(c.Effective_Date__c!=c1.Effective_Date__c && lh.QB_Invoice_Txn_ID__c==null)
{
c.Previous_Start_Date__c=c1.Start_Date__c;
c.Previous_Stop_Date__c=c1.stop_Date__c;
c.Previous_Next_Bill_Amount__c=c1.Next_Bill_Amount_2__c;
c.Previous_Effective_Date__c=c1.Effective_Date__c;
c.Previous_NEXT_INVOICE_AMOUNT_2__c=c1.NEXT_INVOICE_AMOUNT_2__c;
}
}catch(exception e){}}
}
}
if(trigger.isafter)
{
//RETRIEVING THE OLD RECORD TO UPDATE THE FIELDS.
for(can__c c1:trigger.old)
{
for(Can__c c:trigger.new)
{
try{
Invoice_and_Billing_Detail__c lb=[select id,Header_Type__c,Rate__c,Service_Description__c,Start_Date__c,Stop_Date__c
from Invoice_and_Billing_Detail__c where id=:c.Last_Invoice_Detail__c];
system.debug('detailll'+lb);
Invoice_and_Billing_Header__c lh=[select id,QB_Invoice_Txn_ID__c from Invoice_and_Billing_Header__c where id=:c.Last_Invoice_Number__c];
//system.debug('header'+lh);
//EXECUTE ON EFFECTIVE DATE OF OLD RECORD AND THE NEW RECORD ARE NOT SAME AND
//THE FIELD QB INVOICE TXN ID SHOULD BE EMPTY IN INVOICE BILLING HEADER.
if(c.Effective_Date__c!=c1.Effective_Date__c && lh.QB_Invoice_Txn_ID__c==null)
{
lb.Service_Description__c =c.Service_Description__c;
lb.Start_Date__c=c.Start_Date__c;
lb.Stop_Date__c=c.Stop_Date__c;
//if(‘Client Invoice’) then RATE= NEXT_INVOICE_AMOUNT_2__C else NEXT_BILL_AMOUNT_2__C
if(lb.Header_Type__c=='Client Invoice')
{
lb.Rate__c=c.NEXT_INVOICE_AMOUNT_2__C;
}
else{
lb.Rate__c=c.NEXT_BILL_AMOUNT_2__C;
}
update lb;
}
}catch(exception e){}
}
}
}
}
Use these for the logic inside the loops for the bulkification of the triggers
http://boards.developerforce.com/t5/Apex-Code-Development/bulkification-of-trigger/td-p/440083
All Answers
Use these for the logic inside the loops for the bulkification of the triggers
http://boards.developerforce.com/t5/Apex-Code-Development/bulkification-of-trigger/td-p/440083
please dont post duplicate issues so that you can get solution easily