You need to sign in to do that
Don't have an account?
Installfree
Go over object fields with loop
Hi,
I want to send an email notification when case is updated (using trigger).The email should contains the fields that were changed and thier old and new value.
Since our case object fileds can be changed all the time (we have lot of custom fields), I don't want to go over all the fields specifically (difficault to maintenance). I want to go over all case fields with a loop, and compare Trigger.New with Trigger.Old values for each field.
Is it possible? If yes - how?
BTW,
I can't use track history feature, since I have more than 20 fields to track after.
Thanks
Hey
As an example, this:
Would get all accout fields into a Map. More on describe results can be found here:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_dynamic_describe_objects_understanding.htm?SearchType=Stem
Wes
Hi, Thanks for your reply
I have read this page, but don't understand how can I proceed from here.
Even if i have array of fields, I suppose that I can't write
if(trigger.New.Fields[i] == trigger.Old.Fields[i])
How should I proceed from here?
Thanks
I would anticipate something along the lines of:
Map<String, Schema.SObjectField> M = Schema.SObjectType.Account.fields.getMap(); for(String field: m.getKeyset()){ for(Integer i = 0; i < trigger.new.size(); i++){ SObject new = trigger.new[i]; SObject old = trigger.old[i]; if(new.get(field)!=old.get(field)){ // value has changed } } }
I've just typed this up in the browser so there may be some syntax errors.. but that's the gist of it.
Wes