You need to sign in to do that
Don't have an account?
trigger to add currency value of 12 fields
Currently I have a workflow / field update but due to some limitations I want to change this workflow into a trigger
Note: All fields are in same object called object__c,
F1__c,F2__c etc are number fields,
FieldAddAll__c is of type Currency,
Field_1__c, Field_2__c etc are of type currency and the value in these is populated by formula
evaluation criteria: Everytime a record is created or updated
Rule criteria:
OR(OR(RecordTypeId="012333333333",
RecordTypeId="0125555555555",
RecordTypeId="01266666666666"),
OR( ISCHANGED( F1__c ),
ISCHANGED( F2__c ),
ISCHANGED( F3__c ),
ISCHANGED( F4__c ),
ISCHANGED( F5__c ),
ISCHANGED( F6__c ),
ISCHANGED( F7__c ),
ISCHANGED( F8__c ),
ISCHANGED( F9__c ),
ISCHANGED( F10__c ),
ISCHANGED( F11__c ),
ISCHANGED( F12__c ),
))
Field update:
FieldAddAll__c =
( Field_1__c + Field_2__c + Field_3__c + Field_4__c + Field_5__c + Field_6__c + Field_7__c + Field_8__c + Field_9__c + Field_10__c + Field_11__c + Field_12__c )
I want to chnage the above workflow into a trigger. Any help will be appreciated.
Here's some of your code written as a trigger....
Keep in mind it's not all written out but you should have an idea.
To make things even simpler I would just add up your values every time the records are changed just to simplify the trigger as long as the recordtype criteria matches of course
All Answers
Here's some of your code written as a trigger....
Keep in mind it's not all written out but you should have an idea.
To make things even simpler I would just add up your values every time the records are changed just to simplify the trigger as long as the recordtype criteria matches of course
Thanks. I will try this and buidl upon the idea.
Any reason why i am getting this error?
Error: Compile Error: line breaks not allowed in string literals at line 5 column -1
missing a quote on line 5
allowedRecordTypes.add(012V00000004Q5F');
should be
allowedRecordTypes.add('012V00000004Q5F');
Thanks I noticed that after posting it here. Really appreciate your help. Trigger compiled without errors, will test for correctness and let you know the outcome. Will close the post shortly thereafter.
once again thanks.
Thank you very much for your response.
Based on your suggestion and one other member's suggestion this is what i did, seems to be working fine.
Note: requirement changed a bit so got rid of recordtype.
Just keep an eye out for
object__c oldFC = Trigger.oldMap.get(o.Id);
This will throw you an exception on inserts as the old record values do not exist.
in that case should i just say ,
or should i do this -
i would appreciate if you could give me a suggestion. thanks heaps!!
Personally I prefer the second approach but you can split them up as you like. The last thing I can really say which could potentually give you an error is if any of the fields you are adding up is
1) the field not an decimal / integer / double / currency
2)one of those values are null and maybe blank.
Test this senerio out and if you do have that issue there are a few ways to avoid this. Just make sure on your page layout / field level they are required, or check each field individually to validate they are not null / blank before adding them to your final value.
Otherwise it looks great.
Thanks. I appreciate your time and help.
tested scenario 2 . it works fine.
some of these fields are populated in workflow , if not they are required. i guess, i am good there.
once again, Thanks a lot.