You need to sign in to do that
Don't have an account?
Bill Mc
UNKNOWN_EXCEPTION when deleting cases
Hello. I have an APEX class that is scheduled for execution every hour. It finds old cases and deletes them. It has worked for over a year.
Recently, in the last few days, it has started to raise UNKNOWN_EXCEPTION on the line that deletes the cases.
Salesforce support ole me to raise the issue here since I do not have Prem support.
Can anyone help?
Kind regards, Bill
Recently, in the last few days, it has started to raise UNKNOWN_EXCEPTION on the line that deletes the cases.
Salesforce support ole me to raise the issue here since I do not have Prem support.
Can anyone help?
Kind regards, Bill
The debug logs show there are 131 rows.
The APEX code is:
if(cs.size()>0)
{
List<EmailMessage> ems = new List<EmailMessage>();
List<Task> ts = new List<Task>();
System.Debug('cs.size()=' + cs.size());
// ok, we have the Cases, now find the activities
// This might return 0 if the Case is older>1 year and the tasks have been archived to ActivityHistory table
// For those Tasks we will have to bulk delete
ts = new List<Task>([Select Id from Task where WhoId=null And WhatId IN :cs]);
if(ts.size()>0)
{
System.Debug('ts.size()=' + ts.size());
// Great now get the emails
ems = new List<EmailMessage>([Select Id from EmailMessage where ActivityId IN :ts]);
if(ems.size()>0)
{
System.Debug('ems.size()=' + ems.size());
}
else
{
System.Debug('No Emails Found.');
}
}
else
{
System.Debug('No Tasks Found.');
}
// Now reverse delete them (emails, then tasks, then cases)
delete ems;
Log('Deleted ' + ems.size() + ' Emails');
delete ts;
Log('Deleted ' + ts.size() + ' Tasks');
try
{
delete cs;
Log('Deleted ' + cs.size() + ' Cases');
}
catch(System.DmlException ex)
{
System.Debug('Cause: ' + ex.getCause());
System.Debug('Message: ' + ex.getMessage());
System.Debug('TypeName: ' + ex.getTypeName());
System.Debug('getDmlFieldNames: ' + ex.getDmlFieldNames(0));
System.Debug('getDmlFields: ' + ex.getDmlFields(0));
System.Debug('getDmlId: ' + ex.getDmlId(0));
System.Debug('getDmlMessage: ' + ex.getDmlMessage(0));
System.Debug('getDmlType: ' + ex.getDmlType(0));
System.Debug('getNumDml: ' + ex.getNumDml());
}
}
The debug output is:
13:29:16.1 (772234764)|DML_BEGIN|[81]|Op:Delete|Type:Case|Rows:131
13:29:18.3 (2003020988)|DML_END|[81]
13:29:18.3 (2003873005)|EXCEPTION_THROWN|[81]|System.DmlException: Delete failed. First exception on row 0 with id 500D000000zGgs9IAC; first error: UNKNOWN_EXCEPTION, An unknown exception has occurred.: []
13:29:18.3 (2008913917)|USER_DEBUG|[86]|DEBUG|Cause: null
13:29:18.3 (2009085655)|USER_DEBUG|[87]|DEBUG|Message: Delete failed. First exception on row 0 with id 500D000000zGgs9IAC; first error: UNKNOWN_EXCEPTION, An unknown exception has occurred.: []
13:29:18.3 (2009230570)|USER_DEBUG|[88]|DEBUG|TypeName: System.DmlException 13:29:18.3 (2009950885)|USER_DEBUG|[89]|DEBUG|getDmlFieldNames: ()
13:29:18.3 (2010377341)|USER_DEBUG|[90]|DEBUG|getDmlFields: null
13:29:18.3 (2010568592)|USER_DEBUG|[91]|DEBUG|getDmlId: 500D000000zGgs9IAC
13:29:18.3 (2010807407)|USER_DEBUG|[92]|DEBUG|getDmlMessage: An unknown exception has occurred.
13:29:18.3 (2016492287)|USER_DEBUG|[93]|DEBUG|getDmlType: UNKNOWN_EXCEPTION
13:29:18.3 (2016710606)|USER_DEBUG|[94]|DEBUG|getNumDml:
131 13:29:18.3 (2016881373)|SYSTEM_MODE_EXIT|false
However, I also do not see the trace that says "No Tasks Found." either; therefore, there could be something else off. Your comment says there may not be any Tasks. Is it possible that aside from age of the Case that Tasks may exist with WhoId != null ? The exception could be because you are not finding all the Tasks for the Case and as such cannot delete it due to existing relationships. What is the intent of that condition? Should that line be:
Hope that helps.
Sorry, I didn't include all of the log file - just the part after the attempt to delete the cases. The log shows there are 131 of them. (Op:Delete|Type:Case|Rows:131)
It is line #40 (in the code sample in your message) which is causing the exception so that's where I am catching it and printing out the results of some of the methods you suggested.
I dont understand why (and how) we are expected to respond to an "unknown exception". I was told that a Salesforce Developer resource would investigate this - possibly in their own logs to see what the issue - if I posted in this forum.
I dont see enough information to debug this issue and don't really want to go shooting in the dark.
Kind regards,
Bill
P.S. I saw the log showed 131 cases, but I do not see it showing how many Tasks or the message "No Tasks Found." That may be important.
P.P.S. The current information has not proven to be more useful, so you can try replacing the catch block with stack trace which may give you some clues.
I moved the delete of the emails and tasks to inside the IF statements. I also removed the WhoId from the where clause.
In any event, there are no emails or tasks associated with the found cases so there are no attempts to delete emails or tasks.
I added the getStackTraceString to the debugging. The latest log file is below. (There is no log statement that no emails were found because it doesnt search for any if no tasks were found.)
08:23:37.1 (348978902)|SOQL_EXECUTE_BEGIN|[35]|Aggregations:0|SELECT Id FROM Case WHERE (SuppliedEmail LIKE '%customer%' AND SuppliedEmail LIKE '%@whizz%' AND AccountId = NULL AND ContactId = NULL AND Status = 'New' AND CreatedDate < :tmpVar1) ORDER BY CreatedDate ASC NULLS FIRST LIMIT 3000
08:23:37.1 (549260528)|SOQL_EXECUTE_END|[35]|Rows:191
08:23:37.1 (551166085)|USER_DEBUG|[44]|DEBUG|cs.size()=191
08:23:37.1 (552056997)|SOQL_EXECUTE_BEGIN|[49]|Aggregations:0|SELECT Id FROM Task WHERE WhatId IN :tmpVar1
08:23:37.1 (562807143)|SOQL_EXECUTE_END|[49]|Rows:0
08:23:37.1 (563127358)|USER_DEBUG|[75]|DEBUG|No Tasks Found.
08:23:37.1 (563241019)|DML_BEGIN|[80]|Op:Delete|Type:Case|Rows:191
08:23:38.769 (1769419911)|DML_END|[80]
08:23:38.769 (1770402806)|EXCEPTION_THROWN|[80]|System.DmlException: Delete failed. First exception on row 0 with id 500D000000zGh9ZIAS; first error: UNKNOWN_EXCEPTION, An unknown exception has occurred.: []
08:23:38.769 (1777223915)|USER_DEBUG|[85]|DEBUG|Cause: null
08:23:38.769 (1777320363)|USER_DEBUG|[86]|DEBUG|Message: Delete failed. First exception on row 0 with id 500D000000zGh9ZIAS; first error: UNKNOWN_EXCEPTION, An unknown exception has occurred.: []
08:23:38.769 (1777391275)|USER_DEBUG|[87]|DEBUG|TypeName: System.DmlException
08:23:38.769 (1778064408)|USER_DEBUG|[88]|DEBUG|getDmlFieldNames: () 08:23:38.769 (1778391559)|USER_DEBUG|[89]|DEBUG|getDmlFields: null
08:23:38.769 (1778525757)|USER_DEBUG|[90]|DEBUG|getDmlId: 500D000000zGh9ZIAS
08:23:38.769 (1778616962)|USER_DEBUG|[91]|DEBUG|getDmlMessage: An unknown exception has occurred.
08:23:38.769 (1782347933)|USER_DEBUG|[92]|DEBUG|getDmlType: UNKNOWN_EXCEPTION
08:23:38.769 (1782472781)|USER_DEBUG|[93]|DEBUG|getNumDml: 191 08:23:38.769 (1782595610)|USER_DEBUG|[94]|DEBUG|Stack Trace: Class.WhizzCaseDeleter.DeleteCases: line 80, column 1
I really feel quite stuck on how to proceed. Should I not be getting more support from Salesforce?
Bill
Deleting manually is fine - and it would be the same credentials as my own.
Do you know if there is more I can do to attract their attention in this forum?
Bill