I am running a trigger without sharing mode and I am getting this error
Field is not writeable: CaseMilestone.CompletionDate
I used this code in before trigger
cM.CompletionDate = System.now();
Can anybody help me out ?
I am running a trigger without sharing mode and I am getting this error
Field is not writeable: CaseMilestone.CompletionDate
I used this code in before trigger
cM.CompletionDate = System.now();
Can anybody help me out ?
You need to change the status of the milestone and the system will automatically set the completion date/time. You cannot write to this field.
Try below code .. works like a charm ...
trigger CaseMileStoneTestJos on Case (after update) {
Set<Id> caseIds = new Set<Id>();
for (Case record : Trigger.new){
caseIds.add(record.Id);
}
List<CaseMilestone> caseMilestones = [
SELECT
Id
FROM CaseMileStone
WHERE CaseId IN :caseIds
];
for (CaseMileStone cm : caseMilestones) {
cm.CompletionDate = System.today();
}
update caseMilestones;
}