I have come across the process entitlement and milestone which is very useful standard salesforce processes to respond the case and manage the case as per SLA.
Salesforce milestones can only be seen on Feed View of the Case record. But my client won't use feed view so we are in a situation to create a custom response time for the case.
Use case: There is no way to know a case with response time SLA expiring. So we need time count as per priority of the case.
Trigger :
Utilize the supported fields and Owner fields in main SLA Expiry Remaining Time Formula Field
SLA Expiry Remaining Time =
Salesforce milestones can only be seen on Feed View of the Case record. But my client won't use feed view so we are in a situation to create a custom response time for the case.
Use case: There is no way to know a case with response time SLA expiring. So we need time count as per priority of the case.
We have Priorities P1, P2, P3, P4
Timeframe to respond the P1 case is 30 min
Timeframe to respond the P2 case is 2 hour
Timeframe to respond the P3 case is 8 hour
Timeframe to respond the P4 case is 24 hour
- When P1 case is created I need to show the remaining time to respond the case in Custom Field of the object
- Remaining response time should change dynamically when page refreshes
- When Remaining response time count comes down to 0 min send an email alert to case owner saying that the case SLA is expired.
- When Case is assigned to user/owner is changed, Remaining Response time should stop wherever the count it is.
- Case Remaining Response Time should go in negative if SLA is expired.
- Format of the remaining response time should be,
Response Time - 1 hour 30 min (after 30 min of P2 case. Because P2 timeframe is 2 hr)
similarly for remaining priorities
Solution: Formula Field with trigger.
Custom Fields:
- Response Timeframe - Formula Field(Number) - Return 30 min for P1, 120 min P2, 480 for P3, 1440 for P4
- SLA Expiry Remaining Time - Formula Field to show dynamic time count
- SLA Expiry Support Field1 - Number(18,0) - To use in trigger
- SLA Expiry Support Field2 - Number(18,0) - To use in trigger
- Is Owner Changed - Checkbox - Check when owner is changed in Trigger
- Owner Changed On - DateTime - Catch the DateTime when owner changed in Trigger
Response Timeframe =
IF( ISPICKVAL( Priority , 'P1') , 30, IF(ISPICKVAL( Priority , 'P2'), 120, IF(ISPICKVAL( Priority , 'P3'), 480, IF(ISPICKVAL( Priority , 'P4'), 1440, NULL) ) ) )
Trigger :
trigger caseTrigger on Case ( before insert, after insert, before update, after update) {
if(trigger.isAfter && trigger.isInsert){
List<Case> updateList = new List<case>();
List<Id> currentcase = new List<Id>();
for(Case caseLoop : trigger.new){
Case myCase = trigger.new[0];
currentcase.add(myCase.Id);
}
List<Case> updcase = [select id, caseResponseTime__c, CreatedDate, SLA_Expiry_Support2__c from case where id = :currentcase];
for(Case caseLoop : updcase){
//(((CreatedDate + ( caseResponseTime__c /1440 )) - NOW() ) * 24 * 60) / 60;
integer responseTime = integer.valueOf(caseLoop.caseResponseTime__c);
Long createdDate = caseLoop.CreatedDate.addMinutes(responseTime).getTime();
Long currentDate = System.now().getTime();
Long milliseconds = createdDate - currentDate;
Long seconds = milliseconds / 1000;
Long minutes = seconds / 60;
Long hours = minutes / 60;
caseLoop.SLA_Expiry_Support2__c = hours;
updateList.add(caseLoop);
}
if(updateList.size() > 0){
update updateList;
}
}
if(trigger.isBefore && trigger.isUpdate){
for(Case caseLoop : trigger.new){
Case cas= trigger.oldmap.get(caseLoop.Id);
if(caseLoop.OwnerId!= cas.OwnerId){
caseLoop.caseOwnerChanged__c = true;
caseLoop.caseOwnerChangedOn__c = system.now();
//(((CreatedDate + ( ResponseTime__c /1440 )) - caseOwnerChangedOn__c ) * 24 * 60) / 60
integer responseTime = integer.valueOf(caseLoop.caseResponseTime__c);
Long createdDate = caseLoop.CreatedDate.addMinutes(responseTime).getTime();
Long caseOwnerChangedDate = caseLoop.caseOwnerChangedOn__c.getTime();
Long milliseconds = createdDate - caseOwnerChangedDate;
Long seconds = milliseconds / 1000;
Long minutes = seconds / 60;
Long hours = minutes / 60;
caseLoop.SLA_Expiry_Support1__c = hours;
}
else{
caseLoop.caseOwnerChanged__c= false;
}
}
}
Utilize the supported fields and Owner fields in main SLA Expiry Remaining Time Formula Field
SLA Expiry Remaining Time =
IF( caseOwnerChanged__c ,
IF(FLOOR(caseSLAExpirySupport1__c) = 0,
LEFT( TEXT(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - caseOwnerChangedOn__c ) * 24 * 60) ,60)),2 )
&' min',
(TEXT(FLOOR(caseSLAExpirySupport1__c))
&' hour '&
LEFT( TEXT(ABS(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - caseOwnerChangedOn__c ) * 24 * 60) ,60))),2 )
&' min')
),
IF(FLOOR(caseSLAExpirySupport2__c) = 0,
LEFT( TEXT(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - NOW() ) * 24 * 60) ,60)),2 )
&' min',
(TEXT(FLOOR(caseSLAExpirySupport2__c))
&' hour '&
LEFT( TEXT(ABS(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - NOW() ) * 24 * 60) ,60))),2 )
&' min')
)
)
IF(FLOOR(caseSLAExpirySupport1__c) = 0,
LEFT( TEXT(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - caseOwnerChangedOn__c ) * 24 * 60) ,60)),2 )
&' min',
(TEXT(FLOOR(caseSLAExpirySupport1__c))
&' hour '&
LEFT( TEXT(ABS(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - caseOwnerChangedOn__c ) * 24 * 60) ,60))),2 )
&' min')
),
IF(FLOOR(caseSLAExpirySupport2__c) = 0,
LEFT( TEXT(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - NOW() ) * 24 * 60) ,60)),2 )
&' min',
(TEXT(FLOOR(caseSLAExpirySupport2__c))
&' hour '&
LEFT( TEXT(ABS(MOD((((CreatedDate + ( ResponseTime__c /1440 )) - NOW() ) * 24 * 60) ,60))),2 )
&' min')
)
)
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteHadoop Training in Chennai
Dotnet Training in Chennai
thank you for sharing this blog, it is very useful for learning SAP for a beginner. We also provide some tutorials related to this topic.
ReplyDeletejava training in chennai
java training in tambaram
aws training in chennai
aws training in tambaram
python training in chennai
python training in tambaram
selenium training in chennai
selenium training in tambaram
I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge.
ReplyDeletesap training in chennai
sap training in porur
azure training in chennai
azure training in porur
cyber security course in chennai
cyber security course in porur
ethical hacking course in chennai
ethical hacking course in porur
Great Article… I love to read your articles because your writing style is too good,
ReplyDeleteits is very very helpful for all of us and I never get bored
hardware and networking training in chennai
hardware and networking training in omr
xamarin training in chennai
xamarin training in omr
ios training in chennai
ios training in omr
iot training in chennai
iot training in omr
Well we really like to visit this site, many useful information we can get here.
ReplyDeletefull stack developer course