function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lee SinLee Sin 

How do I know what field has been updated in the trigger?

I woud like to get the field name of the updated field in the after update trigger.

So how can I get the name in the trigger?
Atul111Atul111
I can check this is in debug log. This is only way where you can check the change value.

If you like this answer please accept it.
SRKSRK
i have desing a code for your requiremnt 
copy and paste this and create a new class in you org, this class have a method ("getCreatableFieldsSOQL")  that we are going to call from trigger 
method is just taking a string as arrgument that is the name of object on which trigger in written


Apex Class :- 

Public Class GetWritableFields
{
public static list<string> getCreatableFieldsSOQL(String objectName)
{

  String selects = '';
  // Get a map of field name and field token
  Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get(objectName.toLowerCase()).getDescribe().Fields.getMap();
  list<string> selectFields = new list<string>();

  if (fMap != null){
   for (Schema.SObjectField ft : fMap.values()){ // loop through all field tokens (ft)
    Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd)
    if (fd.isCreateable()){ // field is creatable
     selectFields.add(fd.getName());
    }
   }
  }
  return selectFields;

}
}

After saving this class there is a code you need to do in trigger 
Trigger Code :- 

list<string> WritableFields = GetWritableFields.getCreatableFieldsSOQL('<Your Object Name>');  // Replace "<Your Object Name>"


and then just use this  code in you trigger  in the end of code you will have a map "
FieldChangeForTheRecord"  which will have the Id of Record as key and the list of field Name change for that record



string selects ='';
if (!WritableFields.isEmpty()){
            for (string s:WritableFields){
                selects += s + ',';
            }
            if (selects.endsWith(',')){selects = selects.substring(0,selects.lastIndexOf(','));}

        }
String IdSetStr = '(';
for(<Your Object Name> TempObj : Trigger.New)
{
IdSetStr = IdSetStr + '\''+TempObj+'\'';
    IdSetStr = IdSetStr + ',';
}
if (IdSetStr.endsWith(','))
{
     IdSetStr = IdSetStr.substring(0,IdSetStr.lastIndexOf(','));
}
IdSetStr = = IdSetStr +')';
String soql = 'SELECT ' + selects + ' FROM ' + objectName + ' WHERE id in' + IdSetStr;
list<Sobject> UpdatedRecordSobjLst = Database.query(soql);
Map<Id,List<string>> FieldChangeForTheRecord = new Map<Id,List<string>>();
for(String TempFieldName : WritableFields)
{
for(Sobject NewRecordObj : UpdatedRecordSobjLst)
{
  Sobject TempOldSobject = (Sobject)Trigger.OldMap.get(NewRecordObj.Id);
  if(NewRecordObj.get(TempFieldName) != TempOldSobject.get(TempFieldName))
  {
   if(FieldChangeForTheRecord.containskey())
   {
    list<String> TempLst = FieldChangeForTheRecord.get(NewRecordObj.Id);
    TempLst.add(TempFieldName);
    FieldChangeForTheRecord.put(NewRecordObj.Id,TempLst);
   }
   else
   {
    list<String> TempLst = new list<String>();
    TempLst.add(TempFieldName);
    FieldChangeForTheRecord.put(NewRecordObj.Id,TempLst);
   }
  }
}
}
// FieldChangeForTheRecord Map will have the Id of Record as key and the list of field Name change for that record