I wrote a trigger to update the field B with a field A value when we create a record, now I want that field B to update everytime I edit the record. would trigger update the existing record fields ? How to achieve this ? Please look at my code.
Trigger Handler
public void onAfterInsert(){
List<HealthCloudGA__CarePlanGoal__c> percent=[select Name, HealthCloudGA__Progress__c, ProgressToCompletion__c, HealthCloudGA__CarePlanProblem__c from HealthCloudGA__CarePlanGoal__c where Id IN: Trigger.New ];
for(HealthCloudGA__CarePlanGoal__c cent:percent){
if(cent.ProgressToCompletion__c == '0'){
cent.HealthCloudGA__Progress__c=0;
}
else if(cent.ProgressToCompletion__c == '25%'){
cent.HealthCloudGA__Progress__c=0.25;
}
else if(cent.ProgressToCompletion__c == '50%'){
cent.HealthCloudGA__Progress__c=0.50;
}
else if(cent.ProgressToCompletion__c == '75%'){
cent.HealthCloudGA__Progress__c=0.75;
}
else if(cent.ProgressToCompletion__c == '100%'){
cent.HealthCloudGA__Progress__c=1.0;
}
}
update percent;
}
Trigger
MCM_GoalTriggerHandler handler = new MCM_GoalTriggerHandler(trigger.new, trigger.old, trigger.newMap, trigger.oldMap);
if (Trigger.IsUpdate || Trigger.IsInsert)
{
if (Trigger.IsInsert && Trigger.isAfter ){
handler.onAfterInsert();
}