You need to sign in to do that
Don't have an account?
Pete Watson 5
CPU Time Limit Issue On Trigger
Hi All,
Any help on the below would be much appreciated.
have the below trigger and its working perfectly in the sandbox but after deploying to prod I am getting a CPU time limit exeeded failure...
trigger ProfileTrigger on User (before insert, before update) {
List<Id> userIds = new List<Id>();
List<Case> cases = new List<Case>();
List<Case> casesToUpdate = new List<Case>();
for(User u: Trigger.new) {
if(u.out_of_office__c==True) {
userIds.add(u.Id);
}
for (case c : (cases = [SELECT id, Status FROM Case where ownerId IN:userIds]))
IF(c.Status == 'Assigned' || c.Status == 'Working' ||c.Status == 'Escalated'){
c.Reassign_to_Queue__c=true;
casesToUpdate.add(c);
}
update casesToUpdate;
}
Many thanks in advance!
Pete
Any help on the below would be much appreciated.
have the below trigger and its working perfectly in the sandbox but after deploying to prod I am getting a CPU time limit exeeded failure...
trigger ProfileTrigger on User (before insert, before update) {
List<Id> userIds = new List<Id>();
List<Case> cases = new List<Case>();
List<Case> casesToUpdate = new List<Case>();
for(User u: Trigger.new) {
if(u.out_of_office__c==True) {
userIds.add(u.Id);
}
for (case c : (cases = [SELECT id, Status FROM Case where ownerId IN:userIds]))
IF(c.Status == 'Assigned' || c.Status == 'Working' ||c.Status == 'Escalated'){
c.Reassign_to_Queue__c=true;
casesToUpdate.add(c);
}
update casesToUpdate;
}
Many thanks in advance!
Pete
I recommend adding Limits.getCpuTime() to check where there is the maximum consumption is
I suggest comparing the debug logs between your sandbox and production when running this code
Also, review this help article
Anudeep
All Answers
I recommend adding Limits.getCpuTime() to check where there is the maximum consumption is
I suggest comparing the debug logs between your sandbox and production when running this code
Also, review this help article
Anudeep
I see a fundamental errors and not following salesforce best practices which may lead in issues in future. Here is the code for you, please make sure you following the rules mentioned here
https://developer.salesforce.com/index.php?title=Apex_Code_Best_Practices&oldid=26951 (https://developer.salesforce.com/index.php?title=Apex_Code_Best_Practices&oldid=26951)