You need to sign in to do that
Don't have an account?
Edward Scott 5
Set the value of a field to another
Hi Community,
I am trying to write a trigger that will update a field when the value of another field goes up or down by 10%. So I set the initial value of the field equal to the second field but from that point I would like the first field to stay the same until the value of the second field increases or decreases by 10 percent.
I was able to get the field to copy but right now it is updating for every value change of the second field. Any help would be appreciated. I am posting the code below.
I am trying to write a trigger that will update a field when the value of another field goes up or down by 10%. So I set the initial value of the field equal to the second field but from that point I would like the first field to stay the same until the value of the second field increases or decreases by 10 percent.
I was able to get the field to copy but right now it is updating for every value change of the second field. Any help would be appreciated. I am posting the code below.
trigger updateMK on Brief__c (before update, before insert) { for (Brief__c brf : trigger.new){ if (brf.Media_Kit_Needed__c == null){ brf.Media_Kit_Needed__c = integer.valueof(brf.List_Size_Updated_Monthly__c); } else if (brf.Media_Kit_Needed__c <= (.10 * integer.valueof(brf.List_Size_Updated_Monthly__c)) + integer.valueof(brf.List_Size_Updated_Monthly__c)){ brf.Media_Kit_Needed__c = integer.valueof(brf.List_Size_Updated_Monthly__c); } else if (brf.Media_Kit_Needed__c >= (.10 * integer.valueof(brf.List_Size_Updated_Monthly__c)) + integer.valueof(brf.List_Size_Updated_Monthly__c)){ brf.Media_Kit_Needed__c = integer.valueof(brf.List_Size_Updated_Monthly__c); } else{ brf.Media_Kit_Needed__c = brf.Media_Kit_Needed__c; } } }
All Answers
Thanks for your response. I am getting an error on line 18. Compile Error: unexpected token: '{' at line 18 column 12. When I try to change it I can get it to compile but the field just continues to copy the second field.