You need to sign in to do that
Don't have an account?
sieb4me
ERROR:
15:33:36.389 (12389752771)|SOQL_EXECUTE_BEGIN|[1180]|Aggregations:0|select Id from BusinessHours where (TimeZoneSidKey = :tmpVar1 and Name like '08x05%')
15:33:36.389 (12389782974)|EXCEPTION_THROWN|[1180]|System.LimitException: Too many SOQL queries: 101
15:33:36.389 (12389962129)|METHOD_EXIT|[31]|01pG00000045Dj6|CT_CaseTriggerHandler.setBusinessHours(LIST<Case>)
15:33:36.390 (12390066361)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
Class.CT_CaseTriggerHandler.setBusinessHours: line 1180, column 1
Trigger.CaseAfterUpdate: line 31, column 1
15:33:36.390 (12390091595)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
Class.CT_CaseTriggerHandler.setBusinessHours: line 1180, column 1
Trigger.CaseAfterUpdate: line 31, column 1
15:33:36.390 (12390326072)|CODE_UNIT_FINISHED|CaseAfterUpdate on Case trigger event AfterUpdate for [50011000002857m, 500110000028QQu, 50011000002BXoA,
CODE:
//Set the business hours on the case
public static void setBusinessHours(List<Case> lCases)
{
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;
update c;
}
catch (exception e)
{
System.debug ('===== Error in SetBusinessHours: ' + e.getMessage() + ' =====');
}
}
}
}
how to fix this code ...crosses 100 limit
ERROR:
15:33:36.389 (12389752771)|SOQL_EXECUTE_BEGIN|[1180]|Aggregations:0|select Id from BusinessHours where (TimeZoneSidKey = :tmpVar1 and Name like '08x05%')
15:33:36.389 (12389782974)|EXCEPTION_THROWN|[1180]|System.LimitException: Too many SOQL queries: 101
15:33:36.389 (12389962129)|METHOD_EXIT|[31]|01pG00000045Dj6|CT_CaseTriggerHandler.setBusinessHours(LIST<Case>)
15:33:36.390 (12390066361)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
Class.CT_CaseTriggerHandler.setBusinessHours: line 1180, column 1
Trigger.CaseAfterUpdate: line 31, column 1
15:33:36.390 (12390091595)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
Class.CT_CaseTriggerHandler.setBusinessHours: line 1180, column 1
Trigger.CaseAfterUpdate: line 31, column 1
15:33:36.390 (12390326072)|CODE_UNIT_FINISHED|CaseAfterUpdate on Case trigger event AfterUpdate for [50011000002857m, 500110000028QQu, 50011000002BXoA,
CODE:
//Set the business hours on the case
public static void setBusinessHours(List<Case> lCases)
{
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;
update c;
}
catch (exception e)
{
System.debug ('===== Error in SetBusinessHours: ' + e.getMessage() + ' =====');
}
}
}
}
line 1180 is below
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%'].Id;
c.BusinessHoursId = [SELECT Id FROM BusinessHours WHERE TimeZoneSidKey = :c.Case_Timezone__r.TimeZoneSidKey__c AND Name Like '08x05%' LIMIT 1].Id;..it still gives same errors
It will cause Too many soql issues. So please change your code as follow,
1. Remove SOQL Queries within for loop, and query your condition outer loop and process those soql queries list within loop.
2. Create a list and add your for loop processed values within the list and update the list outer the for loop.
Please read best practices and change according to this,
https://developer.salesforce.com/page/Apex_Code_Best_Practices
I have not tested this code, please let me know if any issue
Following line needed change ..thanks once again. This was very helpful.
caseList.put(c.Case_Timezone__r.TimeZoneSidKey__c,bh.Id);
to
caseListMap.put(c.Case_Timezone__r.TimeZoneSidKey__c,bh.Id);
Apex trigger cause exception...AfterUpdate......StringException Invalid Id:America/LosAngeles L External entry point,
Seems like its storing string in Id field. why is that? In Map it seems like you are calling Id, unless I am wrong?
Youe code is good but it always gets one value for business hour.
Its not getting the right business hour since map stores value like this
DEBUG|UUUUU This is my MAPDATA:{Europe/London=01mG00000008TvbIAE}
DEBUG|UUUUU This is my MAPDATA:{Europe/London=01mG00000008TvcIAE}
What do we do to get the right value?
Thanks.