I'm trying to update a custom field on opportunity 'stagechanged__c
' field (Date-datatype) when the standard stage changed from
Prospecting to Qualification.
how to update date on custom field "stagechanged__c
" field when standard stage field changes.
this is my batchjob :
Global class OpportunityStageChanges implements
Database.Batchable<sObject> {
Global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'Select Id,Name,Amount,(Select ID, OldValue, NewValue
from OpportunityFieldHistory)from Opportunity';
System.debug(query);
return Database.getQueryLocator(query);
} Global void execute(Database.BatchableContext BC,
List<Opportunity>
scope) {
for(Opportunity opp : scope) {
for(OpportunityFieldHistory opfh : opp.OpportunityFieldHistory) {
system.debug(opfh.oldValue+'----'+opfh.NewValue );
if(opfh.oldvalue == 'prospecting' && opfh.newvalue == 'Qualification'){
//how to update the stagechanged__c custom field
}
}
}
}
Global void finish(Database.BatchableContext BC) {}
}
how to update the stagechanged field ?
Thanks In Advance, Sekhar