You need to sign in to do that
Don't have an account?
utz1
Resetting running milestone using trigger
Hello,
I am working on enttilement process, where I am updating chechkbox(reset milestone) on case object whenewer milestone is violated. Then my trigger fires which checks whether 'reset milestone' is true or not. If it is true then trigger will fire and milestone will reset. For this i am putting system.now() in start date field on casemilestone object.
Well, My issue is I am able to reset milestone through this processs when i edit case and then save. But I want this procedure should run automatically. When check box get checked then trigger wont fire till i am not editing the case. Is there any way to run this automatically?
Here is the code i am using to reset the milestone.
trigger startdate on Case (after update) {
List<CaseMilestone> cmUpdatedList =new List<CaseMilestone>();
List<Case> cList = [SELECT CaseNumber, AccountId, Id, ContactId, Reset_Milestone__c, Subject, Description, ContactEmail, contact.name, Product__c, SuppliedEmail
FROM Case WHERE Reset_Milestone__c = true AND Id IN :Trigger.new];
List<CaseMilestone> cmList= [SELECT Id , CaseId, StartDate, IsViolated, case.Reset_Milestone__c, IsCompleted FROM CaseMilestone where CaseId =: cList AND IsCompleted = false];
for(case cd : cList)
{
if(cd.Reset_Milestone__c == true )
{
for(CaseMilestone cms : cmList)
{
cms.StartDate = System.now();
system.debug('********cms.StartDate*********'+cms.StartDate);
cmUpdatedList.add(cms);
}
}
Update cmUpdatedList;
}
}
Thanks,
Utz
I am working on enttilement process, where I am updating chechkbox(reset milestone) on case object whenewer milestone is violated. Then my trigger fires which checks whether 'reset milestone' is true or not. If it is true then trigger will fire and milestone will reset. For this i am putting system.now() in start date field on casemilestone object.
Well, My issue is I am able to reset milestone through this processs when i edit case and then save. But I want this procedure should run automatically. When check box get checked then trigger wont fire till i am not editing the case. Is there any way to run this automatically?
Here is the code i am using to reset the milestone.
trigger startdate on Case (after update) {
List<CaseMilestone> cmUpdatedList =new List<CaseMilestone>();
List<Case> cList = [SELECT CaseNumber, AccountId, Id, ContactId, Reset_Milestone__c, Subject, Description, ContactEmail, contact.name, Product__c, SuppliedEmail
FROM Case WHERE Reset_Milestone__c = true AND Id IN :Trigger.new];
List<CaseMilestone> cmList= [SELECT Id , CaseId, StartDate, IsViolated, case.Reset_Milestone__c, IsCompleted FROM CaseMilestone where CaseId =: cList AND IsCompleted = false];
for(case cd : cList)
{
if(cd.Reset_Milestone__c == true )
{
for(CaseMilestone cms : cmList)
{
cms.StartDate = System.now();
system.debug('********cms.StartDate*********'+cms.StartDate);
cmUpdatedList.add(cms);
}
}
Update cmUpdatedList;
}
}
Thanks,
Utz
Not sure of your requirement. You meant the code works if you make update in the saleforce ui on case records but not when you bulk update in code?
If that is what you are looking,then the culprit in line update cmUpdatedList. You have written it inside the for loop of case.It would have resulted in the soql exeception when the records bulk size is higher than 150.
Hopefully this solution works.
Let me know if you need further help.
Thanks and Regards,
Shiva RV
But my problem is when checkbox get checked it reset milestone when we edit and save record on case. I want it should reset automatically when checkbox get checked.
Regards,
utz
I have the same exact requirement, do you know if this worked, we have to implement this automatically as well when a checkbox or a record type changes.
Sanjay
We had similar requirement and we also struggled because case milestone entitlement process was overriding our changes to Start Date with the date specified in the Entitlement process in setup area. Ultimately we took out the dml operation of CaseMilestone update from the class and put into the future method and it seems to be working fine.
Regards,
Ankur