[SalesForce] Closing Service Cloud Case Milestones using Apex

I am having a look at Case milestones and entitlement processes that are part of the service cloud. I want to programmatically close one of the milestones after a certain Status value has been selected in the Case object, as suggested in the Entitlements Best Practice page.

Use Apex code to automatically mark milestones as Completed on cases that match unique criteria. For example, you can create an Apex trigger on EmailMessage that marks a first response milestone as Completed on cases when support reps send email from cases.

However, when I wrote a trigger to attempt this I found out that the IsCompleted field of the CaseMilestone object seems to be unwritable. (I checked in workbench as well and it has updateable : false for the IsCompleted field)

How would I close the milestone as suggested in the best practices docs?

Thanks

Best Answer

You need to populate the CaseMilestone record's CompletionDate that will make the IsCompleted field true.

Related Topic