How to find time delay in Case creation from Salesforce Email-To-Case?

How to find time delay in Case creation from Salesforce Email-To-Case?

Time difference between Case Creation Date and Email Message MessageDate can be used to find time delay in Case creation from Salesforce Email-To-Case.

Sample Code:

for ( EmailMessage objEM : [ 
    SELECT Id, MessageDate, Parent.CreatedDate 
    FROM EmailMessage
    WHERE CreatedDate = TODAY
    AND MessageIdentifier != null
    AND Parent.CreatedDate = TODAY
] ) {
    
    Long caseCreatedDateTime = objEM.Parent.CreatedDate.getTime();
    Long emailReceivedDateTime = objEM.MessageDate.getTime();
    System.debug( 
        'Delay in Seconds: ' + 
        ( caseCreatedDateTime - emailReceivedDateTime ) / 1000
    );
    
}

Output:

Leave a Reply