You need to sign in to do that
Don't have an account?
how to update all the Records using trigger
Hi,
I want update cost field in raw custom obj.All records need to be update when i update one record.
I wrote some code its not working properly
trigger:
=========================
trigger costincr on Raw__c (before update) {
list<raw__c> raw= new list<raw__c>();
raw=[select id,name,cost__c,Exp_Date__c from Raw__c ];
cost_incr w=new cost_incr();
w.incr_method(raw);
}
class:
===================
public class cost_incr{
public void incr_method(raw__c[] raw){
raw=[select id,name,cost__c,Exp_Date__c from Raw__c ];
for(raw__c rec:raw)
{
if(rec.cost__c!=null)
{
rec.cost__c=rec.cost__c+55;
}
}
update raw;
}
}
Thanks
Hi
I don't know whether i understood what you excatly need
I think please try this
In this code add
trigger costincr on Raw__c (before update) {
list<raw__c> raw= new list<raw__c>();
raw=[select id,name,cost__c,Exp_Date__c from Raw__c ];
//cost_incr w=new cost_incr();
for(cost_incr w : Trigger.new){
w.incr_method(raw);
}
}
Thanks
Anu
Hi,
You have a recursive trigger. Your before-update trigger call the class to update Raw__c records and it causes the same trigger to fire again.
See how to control a recursive trigger here:
http://www.salesforce.com/docs/developer/cookbook/Content/apex_controlling_recursive_triggers.htm
Regards,
Hengky