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

How to use list in this trigger
Hi,
Here Im trying to create a trigger where there is master object (Custom object-Opportunity) and child object(RFP).
Im mapping values from other object (Ratecard) when i entered some parameters in RFP.
In RFP there are some parameters(CompletesRequired,BID,Incidence rate,Market,Audience,Ratecard).We have same fields in Ratecard object with Actual CPI (currency) which we are uploading through dataloader.
When i entered these parameters in RFP the ActualCpi will populate automatically in RFP Object.
this scenario is working for one RFP entry.How can i use lists in this case for multiple rfp entry.
trigger RFPupdate on RFP__c (before insert, before update) {
Set<Decimal> comp = new Set<Decimal>();
Set<Decimal> bid = new Set<Decimal>();
Set<Decimal> inc = new Set<Decimal>();
List<String> aud = new List<String>();
List<String> stage = new List<String>();
List<String> stage2 = new List<String>();
List<String> market=new List<String>();
List<String> ratecard =new List<String>();
List<Id> opp=new List<Id>();
for(RFP__c r : trigger.new){
if(r.Completes_Required__c != null){
comp.add(r.Completes_Required__c);
}
if(r.Bid_LOI_in_minutes__c != null){
bid.add(r.Bid_LOI_in_minutes__c);
}
if(r.Incidence_Rate__c != null)
{
inc.add(r.Incidence_Rate__c);
}
if((r.Audience__c == 'B2B' || r.Audience__c == 'Gen Pop') && r.Stage__c == 'RFP_Received')
{
aud.add(r.Audience__c);
}
if(r.Market__c != null)
{
market.add(r.Market__c);
}
if(r.Rate_Card__c != null)
{
ratecard.add(r.Rate_Card__c);
}
if(r.Opportunity__c!=null)
{
opp.add(r.Opportunity__c);
system.debug('Opp*****'+opp);
}
}
//If audience is B2B or Genpop
try{
if(aud.size()> 0){
Map<Decimal, CPI__c> cpi1 = new Map<Decimal, CPI__c>();
for(CPI__c obj1 : [SELECT Id, Bid_LOI_in_minutes__c,Actual_CPI__c,Incidence_Rate__c,Actual_CPIchanged__c,Audience__c,Stage__c, Completes_Required__c,Name,Market__c FROM CPI__c WHERE (Bid_LOI_in_minutes__c IN :bid
AND Completes_Required__c IN: comp AND Incidence_Rate__c IN:inc AND Audience__c IN:aud AND Name IN:ratecard AND Market__c IN:market )]){
cpi1.put(obj1.Completes_Required__c , obj1);
system.debug('CPI'+cpi1);
}
// We have all the reference data we need, last loop on the each Opportunity
if(cpi1.size()>0){
system.debug('CPISize@@@@@@@'+cpi1.size());
for(RFP__c rf1: trigger.new){
system.debug('^^^^^^^^^^^^^^^RFP'+rf1);
rf1.Actual_CPI__c = cpi1.get(rf1.Completes_Required__c).Actual_CPIchanged__c;
system.debug('ActualCPI################'+rf1.Actual_CPI__c);
if(rf1.Proposed_CPI__c == 0.00 ){
rf1.Proposed_CPI__c= cpi1.get(rf1.Completes_Required__c).Actual_CPIchanged__c;
system.debug('ProposedCPI##############'+rf1.Proposed_CPI__c);
}
}
}
else{
for(RFP__c rf1 : trigger.new){
rf1.Actual_CPI__c =0.00;
}
}
}
}
catch(exception e){
}
}
From what I've read and understood - I suppose you should go for Bulk triggers if the requirement is to set the trigger for multiple row entries :
http://developer.force.com/cookbook/recipe/trigger-pattern-for-tidy-streamlined-bulkified-triggers
http://salesforce.stackexchange.com/questions/12981/why-should-we-use-bulk-triggers
Hi amrit,
I think below code will help you.
Thanks for your reply.
i tried your code.ActualCPI value will update when i entered the parameters.The Actual CPI value in RFPobject shows different value compared with Actual CPI in Ratecard object.When i edit the record it saves correct Actual CPI value in Ratecard object.This only happens when i go for multiple entries.eg:
Firstentry -Completesreq- 200 , BID-20, Incidencerate-10 ,Market-India, Audience-B2B ,Ratecard -Decision , Actual CPI-4.20
Sec entry-Completesreq- 200 , BID-10, Incidencerate-20 ,Market-Argentina, Audience-GenPop , Ratecard- General ,Actual CPI-4.20
Here Actual CPI for sec entry is 22.60.It shows 4.20 only
Why is it so?
Hi Sonam.
Thanks for your reply