You need to sign in to do that
Don't have an account?
HARISH S 11
old opportunity amount less than new opportunity amount
Hi Guys,
Am new to salesforece and thisis my fist trigger. So my requirement is if am trying to update an opportunity record and if the new amoutn is less tha the old amount I should get and error else it should alow me to update the record.
I tried the belwo but doesn't seem to work, Could somebody please help me?
trigger old_new_amount_check on Opportunity (before update) {
For (opportunity a: Trigger.New){
Opportunity oldAmount = Trigger.oldMap.get(a.Amount);
if(a.Amount<a.oldAmount){
a.addError('New Amount is less that old AMount');
}
else{
System.debug('Opportunity AMount Updated');
}
}
}
Am new to salesforece and thisis my fist trigger. So my requirement is if am trying to update an opportunity record and if the new amoutn is less tha the old amount I should get and error else it should alow me to update the record.
I tried the belwo but doesn't seem to work, Could somebody please help me?
trigger old_new_amount_check on Opportunity (before update) {
For (opportunity a: Trigger.New){
Opportunity oldAmount = Trigger.oldMap.get(a.Amount);
if(a.Amount<a.oldAmount){
a.addError('New Amount is less that old AMount');
}
else{
System.debug('Opportunity AMount Updated');
}
}
}
trigger old_new_amount_check on Opportunity(before update) {
For(opportunity a: Trigger.New) {
Opportunity oldOpty = Trigger.oldMap.get(a.Id);
if (a.Amount < oldOpty.Amount ) {
a.addError('New Amount is less that old AMount');
} else {
System.debug('Opportunity AMount Updated');
}
}
}
Regards,
Pawan Kumar
All Answers
trigger old_new_amount_check on Opportunity(before update) {
For(opportunity a: Trigger.New) {
Opportunity oldOpty = Trigger.oldMap.get(a.Id);
if (a.Amount < oldOpty.Amount ) {
a.addError('New Amount is less that old AMount');
} else {
System.debug('Opportunity AMount Updated');
}
}
}
Regards,
Pawan Kumar
Thanks a lot.