You need to sign in to do that
Don't have an account?
Rajesh SFDC
how to get last modified field values from case history object
here my requirments i want to get whose last modified fileds values to update to case object
using apex trigger
here my code given below:
trigger TrackigHistory on Case (before update)
{
set<Id> setId = new set<Id>();
string strhistory;
for(Case con: trigger.new)
{
setId.add(con.Id);
List<CaseHistory> ch = [Select id,CaseId, Field, NewValue, OldValue from CaseHistory where CaseId = :setId ];
system.debug('&&&&&&&CaseHistory size&&&&&&&&&&'+ch.size());
// for(integer i=0;i<ch.size();i++)
for(CaseHistory c: ch)
{
// if(ch[i].Field != NULL && ch[i].OldValue != NULL && ch[i].NewValue != NULL)
//{
system.debug('&&&&&&&CaseHistory&&&&&&&&& '+'Field '+c.Field +' Changed from ' +c.OldValue+' to ' +c.NewValue);
con.Track_status_history__c = 'Field '+c.Field +' Changed from ' +c.OldValue+' to ' +c.NewValue;
how to get fields values last modified field values updat to case object
//}
}
}
}
using apex trigger
here my code given below:
trigger TrackigHistory on Case (before update)
{
set<Id> setId = new set<Id>();
string strhistory;
for(Case con: trigger.new)
{
setId.add(con.Id);
List<CaseHistory> ch = [Select id,CaseId, Field, NewValue, OldValue from CaseHistory where CaseId = :setId ];
system.debug('&&&&&&&CaseHistory size&&&&&&&&&&'+ch.size());
// for(integer i=0;i<ch.size();i++)
for(CaseHistory c: ch)
{
// if(ch[i].Field != NULL && ch[i].OldValue != NULL && ch[i].NewValue != NULL)
//{
system.debug('&&&&&&&CaseHistory&&&&&&&&& '+'Field '+c.Field +' Changed from ' +c.OldValue+' to ' +c.NewValue);
con.Track_status_history__c = 'Field '+c.Field +' Changed from ' +c.OldValue+' to ' +c.NewValue;
how to get fields values last modified field values updat to case object
//}
}
}
}
History objects will track the fields which are set for field history tracking and not all fields are trackable, whereas using context varaibles you can fetch the details for almost all the fields.
Will this work for you?
Last Modified Values are available in the After Update event not in the Before Update. The record is not yet updated, hence you won't get the Last Modified values. Try to address the scenario in different way and you will be all set.
Note : If this answers your question, please mark this as Answered, thus helping others.