+ Start a Discussion
:) :) :) :) :):) :) :) :) :) 

How to bind or concat String with Trigger.new foreach statement.

I am trying to get all fields API name using getDescribe() and want to use them to bind with triggers foreach statement but couldn't figured out the way to do it. Please Help

Trigger myleadTrigger on lead(after update) {

Lead<String> leadFieldsApiNames = new Lead<String>();
Map<String, SobjectField> fieldMap = Lead.getsObjectType().getDescribe().Fields.getMap();

for(String f :  fieldMap.keySet()) {
leadFieldsApiNames.add(fieldMap.get(f).getDescribe().getName()));
}
for(String s : leadFieldsApiNames){
for(Lead TN : Trigger.new){
 for(Lead TO : Trigger.old){

  if(TO.S != TN.S){
        System.debug('Value has been chaged '+TN.S);
         }

       }
    }
  }
}
ShashForceShashForce
Hi,

Can you please explain more what you are trying to achieve with your code?

Thanks,
Shashank
:) :) :) :) :):) :) :) :) :)
Thanks for replying.

I want to bind or concat string variable (which is field API Name) with foreach temp (Trigger.new foreach temp variable)  variable inside the foreach (trigger.new foreach). Please look and understand the above code you'll know what i am asking? 


ShashForceShashForce
All I can understand is that you are checking if a particular field value is changing. But not sure if that can be achieved with your code.

TO.S != TN.S does not work. S is not a field on Lead object. Using a string which contais the value of the field name will not work.