• Sandy
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
As per current implementation, my Case Detailed page is pure custom and I have Entitlement Processes and Milestones in place. The thing is that I cant access the Milestone Status Icon field, but I can access the MilestoneStatus value. That value I need to populate into Custom Milestone Status Icon and using formula field I wants to show the Milestone Status Icon.
I got the reference here : https://help.salesforce.com/articleView?id=000171150&language=en_US&type=1

How can I approach to this implementation ?
  • May 04, 2022
  • Like
  • 0
trigger CompleteResolutionTimeMilestone on Case (after update) {
  if (UserInfo.getUserType() == 'Standard'){
     DateTime completionDate = System.now();
     List<Id> updateCases = new List<Id>();
     for (Case c : Trigger.new){
         if (((c.isClosed == true)||(c.Status == 'Closed'))&&         ((c.SlaStartDate <= completionDate)&&(c.SlaExitDate == null)))          updateCases.add(c.Id); }
if (updateCases.isEmpty() == false) milestoneUtils.completeMilestone(updateCases, 'Resolution Time', completionDate); } }

error is : CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY : DefaultEntitlement: execution of AfterUpdate

caused by: System.FinalException: Record is read-only

Thanks in advance.
  • May 01, 2022
  • Like
  • 0
Hi!
Please can someone assist me with two triggers that I am trying to get working on for the Case object. 
first trigget is for automatically assign entitlements to cases from email or web. and second one is complete resolution time when case is closed.
Here are the two triggers as currently written - appreciate that they probably need work! :-)
Thanks in advance.

Trigger 1
trigger DefaultEntitlement on Case (Before Insert, Before Update) {
    Set<Id> contactIds = new Set<Id>();
    Set<Id> acctIds = new Set<Id>();
    for (Case c : Trigger.new) {
        contactIds.add(c.ContactId);
        acctIds.add(c.AccountId);
    }
    List <EntitlementContact> entlContacts = 
                [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId 
                From EntitlementContact e
                Where e.ContactId in :contactIds
                And e.Entitlement.EndDate >= Today 
                And e.Entitlement.StartDate <= Today];
    if(entlContacts.isEmpty()==false){
        for(Case c : Trigger.new){
            if(c.EntitlementId == null && c.ContactId != null){
                for(EntitlementContact ec:entlContacts){
                    if(ec.ContactId==c.ContactId){
                        c.EntitlementId = ec.EntitlementId;
                        if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                            c.AssetId=ec.Entitlement.AssetId;
                        break;
                    }
                } 
            }
        } 
    } else{
        List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, 
                e.AccountId, e.AssetId
                From Entitlement e
                Where e.AccountId in :acctIds And e.EndDate >= Today 
                And e.StartDate <= Today];
        if(entls.isEmpty()==false){
            for(Case c : Trigger.new){
                if(c.EntitlementId == null && c.AccountId != null){
                    for(Entitlement e:entls){
                        if(e.AccountId==c.AccountId){
                            c.EntitlementId = e.Id;
                            if(c.AssetId==null && e.AssetId!=null)
                                c.AssetId=e.AssetId;
                            break;
                        }
                    } 
                }
            } 
        }
    }
}

Trigger 2

trigger CompleteResolutionTimeMilestone on Case (before update) {
    if (UserInfo.getUserType() == 'Standard'){
        DateTime completionDate = System.now(); 
            List<Id> updateCases = new List<Id>();
            for (Case c : Trigger.new){
                    if (((c.isClosed == true)||(c.Status == 'Closed'))&&((c.SlaStartDate 
                        <= completionDate)&&(c.SlaExitDate == null)))
                   updateCases.add(c.Id);
                c.EntitlementId = null;
        }
    if (updateCases.isEmpty() == false)
        milestoneUtils.completeMilestone(updateCases, 'Resolution Time', completionDate);
    }
}
  • April 29, 2022
  • Like
  • 0
Hi guys,

Can anyone help me with a trigger requirment. I am looking to automatically assign an entitlement to a case based on the entitlement that is related to the Account associated to the Case.

I need it to work via email to case, web to case and manual update.
  • October 26, 2016
  • Like
  • 0