You need to sign in to do that
Don't have an account?
trigger help
hi i am new to bulkification please help me bulkify this trigger
/*This trigger creates Custom Revenue Schedules depending
on the size of opportunitylineitemschedule when a opportunity line item is updated*/
trigger CreateCloneScheduleRevenue on OpportunityLineItem (after update)
{
//creating new list of custom revenue schedules
public list<Custom_Revenue_Schedule__c > CRSSList {get;set;}
CRSSList =new list<Custom_Revenue_Schedule__c >();
//initializing set of pricebookid's
set<id> pricebookid=new set<id>();
//initializing set of opporunitylineitemid's
set<id> oliid=new set<id>();
id opp;
//adding the pricebookentryid and opportunitylineitem id'd to the set
for(opportunitylineitem ols:trigger.new)
{
pricebookid.add(ols.pricebookentryid);
oliid.add(ols.id);
opp=ols.opportunityid;
}
//retriveing pricebookentryid
pricebookentry pbe=[select id,Product2Id from pricebookentry where id=:pricebookid];
//retrieving product2 id
product2 p2=[select id from product2 where id=:pbe.product2id];
Custom_Revenue_Schedule__c[] c=[select id from Custom_Revenue_Schedule__c where Product__c=:p2.id];
//deleting the custom revenue schedules if size is greater than 0
if(c.size()>0)
{
delete c;
}
//creating new custom revenue schedules depending on the size of opportunitylineitemschedule
opportunitylineitemschedule[] olsc=[select id,Quantity,Revenue,ScheduleDate from opportunitylineitemschedule where opportunitylineitemid=:oliid];
for(opportunitylineitemschedule olsc1:olsc)
{
Custom_Revenue_Schedule__c c1=new Custom_Revenue_Schedule__c();
c1.Schedule_Revenue__c=olsc1.Revenue;
c1.Date__c=olsc1.ScheduleDate;
c1.Opportunity__c=opp;
c1.Product__c=p2.id;
CRSSList .add(c1);
}
insert CRSSList ;
}