You need to sign in to do that
Don't have an account?
sieb4me
code fix
Hi,
following code gets me the bus hours for case but its getting wrong bus hour id.
Because debug log shows values stored is like this in map
{Europe/London=01mG00000008TvcIAE}
{Europe/London=01mG00000008TvbIAE}
-----
--it should simulate this code--
-----
List<Case> caseList = [SELECT Id, BusinessHoursId, EntitlementId, Entitlement.SlaProcess.Name, Case_Timezone__r.TimeZoneSidKey__c FROM Case WHERE Id in :lCases];
for (Case c :caseList)
{
if (c.EntitlementId != null)
{
try
{
if (c.Entitlement.SlaProcess.Name == 'Mission Critical' || c.Entitlement.SlaProcess.Name == 'Mission Critical (GCS Management Override)')
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%'].Id;
else if (c.Entitlement.SlaProcess.Name == 'Enterprise' || c.Entitlement.SlaProcess.Name == 'Enterprise (GCS Management Override)')
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%'].Id;
else if (c.Entitlement.SlaProcess.Name == 'Standard')
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%'].Id;
System.debug ('====C'+ c + '====BID'+ c.BusinessHoursId);
update c;
-----
CURRENT CODE to fix that gets wrong business hours:
----------------------------------------------------------------------------------
List<Case> caseList = [SELECT Id, BusinessHoursId, EntitlementId, Entitlement.SlaProcess.Name, Case_Timezone__r.TimeZoneSidKey__c FROM Case WHERE Id in :lCases];
List<BusinessHours> bHours=[SELECT Id FROM BusinessHours WHERE Name Like '08x05%'];
List<case> caseListUpdate = new List<case>{};
Map<String,Id> caseListMap=new Map<String,Id>();
for(BusinessHours bh:bHours)
{
for(Case c:caseList)
{
caseListMap.put(c.Case_Timezone__r.TimeZoneSidKey__c,bh.Id);
}
}
System.debug('######This is my MAPDATA:'+ caseListMap);
for (Case c :caseList)
{
if (c.EntitlementId != null)
{
try
{
Boolean bEntryCriteria = caseListMap != null && c.Case_Timezone__c != null && c.Case_Timezone__r.TimeZoneSidKey__c != null && caseListMap.containsKey(c.Case_Timezone__r.TimeZoneSidKey__c);
if (bEntryCriteria && (caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != null || caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != ''))
{
// if (caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != null || caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != '')
// {
if (c.Entitlement.SlaProcess.Name != null && c.Entitlement.SlaProcess.Name == 'Mission Critical' || c.Entitlement.SlaProcess.Name == 'Mission Critical (GCS Management Override)')
c.BusinessHoursId = caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c);
else if (c.Entitlement.SlaProcess.Name != null && c.Entitlement.SlaProcess.Name == 'Enterprise' || c.Entitlement.SlaProcess.Name == 'Enterprise (GCS Management Override)')
c.BusinessHoursId = caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c);
else if (c.Entitlement.SlaProcess.Name != null && c.Entitlement.SlaProcess.Name == 'Standard')
c.BusinessHoursId = caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c);
// }
following code gets me the bus hours for case but its getting wrong bus hour id.
Because debug log shows values stored is like this in map
{Europe/London=01mG00000008TvcIAE}
{Europe/London=01mG00000008TvbIAE}
-----
--it should simulate this code--
-----
List<Case> caseList = [SELECT Id, BusinessHoursId, EntitlementId, Entitlement.SlaProcess.Name, Case_Timezone__r.TimeZoneSidKey__c FROM Case WHERE Id in :lCases];
for (Case c :caseList)
{
if (c.EntitlementId != null)
{
try
{
if (c.Entitlement.SlaProcess.Name == 'Mission Critical' || c.Entitlement.SlaProcess.Name == 'Mission Critical (GCS Management Override)')
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%'].Id;
else if (c.Entitlement.SlaProcess.Name == 'Enterprise' || c.Entitlement.SlaProcess.Name == 'Enterprise (GCS Management Override)')
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%'].Id;
else if (c.Entitlement.SlaProcess.Name == 'Standard')
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%'].Id;
System.debug ('====C'+ c + '====BID'+ c.BusinessHoursId);
update c;
-----
CURRENT CODE to fix that gets wrong business hours:
----------------------------------------------------------------------------------
List<Case> caseList = [SELECT Id, BusinessHoursId, EntitlementId, Entitlement.SlaProcess.Name, Case_Timezone__r.TimeZoneSidKey__c FROM Case WHERE Id in :lCases];
List<BusinessHours> bHours=[SELECT Id FROM BusinessHours WHERE Name Like '08x05%'];
List<case> caseListUpdate = new List<case>{};
Map<String,Id> caseListMap=new Map<String,Id>();
for(BusinessHours bh:bHours)
{
for(Case c:caseList)
{
caseListMap.put(c.Case_Timezone__r.TimeZoneSidKey__c,bh.Id);
}
}
System.debug('######This is my MAPDATA:'+ caseListMap);
for (Case c :caseList)
{
if (c.EntitlementId != null)
{
try
{
Boolean bEntryCriteria = caseListMap != null && c.Case_Timezone__c != null && c.Case_Timezone__r.TimeZoneSidKey__c != null && caseListMap.containsKey(c.Case_Timezone__r.TimeZoneSidKey__c);
if (bEntryCriteria && (caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != null || caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != ''))
{
// if (caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != null || caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c) != '')
// {
if (c.Entitlement.SlaProcess.Name != null && c.Entitlement.SlaProcess.Name == 'Mission Critical' || c.Entitlement.SlaProcess.Name == 'Mission Critical (GCS Management Override)')
c.BusinessHoursId = caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c);
else if (c.Entitlement.SlaProcess.Name != null && c.Entitlement.SlaProcess.Name == 'Enterprise' || c.Entitlement.SlaProcess.Name == 'Enterprise (GCS Management Override)')
c.BusinessHoursId = caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c);
else if (c.Entitlement.SlaProcess.Name != null && c.Entitlement.SlaProcess.Name == 'Standard')
c.BusinessHoursId = caseListMap.get(c.Case_Timezone__r.TimeZoneSidKey__c);
// }
One thing I've noticed in the part where you said the code is working...You have three if conditions but inside them the all execute the same statement..so why having three different if conditions...?
I have refactored the code and hope it should give you the correct BusinessHoursId, please see the code below....
Hope it helps !