You need to sign in to do that
Don't have an account?
Hector Diaz
Trigger just fire one time
Hi
My trigger fires every time when the record its updated, how to prevent because i need to fire just once.
thanks in advance.
trigger QARejectUpdatesOppStage1_RAMU_VINIT_3 on QA_Order_Control__c(after insert,before update){
system.debug('===========');
//Unlock opportunity
//Update the opportunity stage to '08. Delivery Invoiced' for 17.Invoiced QAOC and update the QAOC to the opportunity page
Map<Id,Id> oppQAIdMap=new Map<Id,Id>();
for(QA_Order_Control__c qaoc:Trigger.New){
if(qaoc.Status__c=='17. Invoiced'&& qaoc.Country_user__c=='MX') {
oppQAIdMap.put(qaoc.Opportunity__c,qaoc.id);
}
}
//Update fields
list<Opportunity> listOpps=new list<Opportunity>();
listOpps=[Select id,StageName,QA_Order_Control__c from Opportunity where id IN:oppQAIdMap.keySet()];
for(Opportunity opp:listOpps){
opp.StageName='08. Delivery Invoiced';
opp.QA_Order_Control__c=oppQAIdMap.get(opp.id);
opp.Block_Sales_Team__c= false;
opp.Advise__c=false;
//update this field
opp.CloseDate=date.today();
}
if(!listOpps.isEmpty()){
try{
update listOpps;
}catch(System.Dmlexception e){
system.debug (e);
}
}
}
My trigger fires every time when the record its updated, how to prevent because i need to fire just once.
thanks in advance.
trigger QARejectUpdatesOppStage1_RAMU_VINIT_3 on QA_Order_Control__c(after insert,before update){
system.debug('===========');
//Unlock opportunity
//Update the opportunity stage to '08. Delivery Invoiced' for 17.Invoiced QAOC and update the QAOC to the opportunity page
Map<Id,Id> oppQAIdMap=new Map<Id,Id>();
for(QA_Order_Control__c qaoc:Trigger.New){
if(qaoc.Status__c=='17. Invoiced'&& qaoc.Country_user__c=='MX') {
oppQAIdMap.put(qaoc.Opportunity__c,qaoc.id);
}
}
//Update fields
list<Opportunity> listOpps=new list<Opportunity>();
listOpps=[Select id,StageName,QA_Order_Control__c from Opportunity where id IN:oppQAIdMap.keySet()];
for(Opportunity opp:listOpps){
opp.StageName='08. Delivery Invoiced';
opp.QA_Order_Control__c=oppQAIdMap.get(opp.id);
opp.Block_Sales_Team__c= false;
opp.Advise__c=false;
//update this field
opp.CloseDate=date.today();
}
if(!listOpps.isEmpty()){
try{
update listOpps;
}catch(System.Dmlexception e){
system.debug (e);
}
}
}
Triggers are at the object level and will fire based on the triggering event.In above trigger, trigger will fired for every record insert and updates.
Trigger will process only records which are satisfying if(qaoc.Status__c=='17. Invoiced'&& qaoc.Country_user__c=='MX') condition.
thanks for your answer, but may be exists code for stooping the loop and fire just once, what do you thing?
best