You need to sign in to do that
Don't have an account?

apex trigger
// the below sample code showing me error
if(Trigger.isBefore && Trigger.isUpdate )
{
for(Lead led:Trigger.new)
{
string compnayname='company';
Lead oldled= Trigger.oldMap.get(led.ID);
if(oldled.compnayname!=led.compnayname)// ERROR : there is no such field company name :( (But there I am using the variable name instead of using field API directly, to acheive the requirement. Could plese tell me how to acheive this using the variable name)
{
leadids.add(ld.id);
}
}
if(Trigger.isBefore && Trigger.isUpdate )
{
for(Lead led:Trigger.new)
{
string compnayname='company';
Lead oldled= Trigger.oldMap.get(led.ID);
if(oldled.compnayname!=led.compnayname)// ERROR : there is no such field company name :( (But there I am using the variable name instead of using field API directly, to acheive the requirement. Could plese tell me how to acheive this using the variable name)
{
leadids.add(ld.id);
}
}
If want to know the API name of the field, then go to that Object->Fields, it will disaply the API name of the field which you want to access
@karanraj - thanks for reply, But I need to use field API name dynamically and need to check old values and news values aren't same!!
Is there any way to use it dynamically >>>>>>>>>>>
Map<String, Schema.SObjectField> fieldsMap = Schema.SObjectType.Lead.fields.getMap();
for(String key : fieldsMap.keySet()){
Schema.DescribeFieldResult result = fieldsMap.get(key).getDescribe();
if(!result.isNillable() && result.isCreateable()) {
System.debug(logginglevel.info, '+++++++++ result = '+result.getName());
}
}