You need to sign in to do that
Don't have an account?
louisa barrett 7
Apex trigger to update field
Hi,
I was wondering if anyone could offer some advice whether the below trigger is sufficent or whether additonal checks or improvements are required.
trigger UpdatePurchaseOrderNumber on Opportunity (before update) {
for(Opportunity opp:trigger.new){
opp.Purchase_Order_No__c = opp.Sales_Order_Number__C;
}
}
Basically, I need to simply copy the Sales_Order_Number field to the Purchase Order No field before any validations are performed on the Opportunity when the Save is pressed. The purchase order has a validation rule set on it that it cannot be null when the Opportunity is saved, so I cannot use a workflow.
Thanks
I was wondering if anyone could offer some advice whether the below trigger is sufficent or whether additonal checks or improvements are required.
trigger UpdatePurchaseOrderNumber on Opportunity (before update) {
for(Opportunity opp:trigger.new){
opp.Purchase_Order_No__c = opp.Sales_Order_Number__C;
}
}
Basically, I need to simply copy the Sales_Order_Number field to the Purchase Order No field before any validations are performed on the Opportunity when the Save is pressed. The purchase order has a validation rule set on it that it cannot be null when the Opportunity is saved, so I cannot use a workflow.
Thanks
for(Opportunity opp:trigger.new){
opp.Purchase_Order_No__c = opp.Sales_Order_Number__C;
update opp;
}
}
All Answers
for(Opportunity opp:trigger.new){
opp.Purchase_Order_No__c = opp.Sales_Order_Number__C;
update opp;
}
}