You need to sign in to do that
Don't have an account?
PROCENTEC TechSupport
How to track date/time of last activity within a case
Hello,
I know this has been discussed many times, however I cannot find an answer after breaking my skull open with this issue all day and yesterday. I have only been working with SalesForce for a week so forgive me if this is simple to do.
Problem:
Case.LastModifiedDate only reflects the date/time that the actual case was modified, and not the date/time of the last activity within a case.
My goal/solution:
Since Case.LastModifiedDate is a read-only field, I have created a custom field named Case.LastModifiedDateActivity. I want Case.LastModifiedDateActivity (DATETIME datatype) to be automatically updated (via Apex) whenever an employee performs an activity related to a certain case. (When the employee writes an email to a customer, makes a phone call, etc. in regards to a certain case).
Can someone help me implement this function? It is vital for our support team!
I know this has been discussed many times, however I cannot find an answer after breaking my skull open with this issue all day and yesterday. I have only been working with SalesForce for a week so forgive me if this is simple to do.
Problem:
Case.LastModifiedDate only reflects the date/time that the actual case was modified, and not the date/time of the last activity within a case.
My goal/solution:
Since Case.LastModifiedDate is a read-only field, I have created a custom field named Case.LastModifiedDateActivity. I want Case.LastModifiedDateActivity (DATETIME datatype) to be automatically updated (via Apex) whenever an employee performs an activity related to a certain case. (When the employee writes an email to a customer, makes a phone call, etc. in regards to a certain case).
Can someone help me implement this function? It is vital for our support team!
You can try creating a simple trigger on your cases, along the lines of;
Since you're new to Salesforce, I feel I need to mention that you would write this in the sandbox, then write a test class for it, and then deploy both to production.
All Answers
You can try this private appexchange package: https://appexchange.salesforce.com/listingDetail?listingId=a0N300000016cUoEAI
However, it will only do it for call logs. For email message, you can use a workflow rule on "Email Message".
Thanks,
Shashank
You can try creating a simple trigger on your cases, along the lines of;
Since you're new to Salesforce, I feel I need to mention that you would write this in the sandbox, then write a test class for it, and then deploy both to production.
Shashank - I have tried the touch up trigger script already, before posting this thread. As an Apex noobie, that script is too complex for me to integrate since I don't understand it that well. I was looking for something similar to Kevin's response, however that too won't fully work here.
Kevin - Your trigger script is exactly what I was getting at, unfortunately I don't think I can implement it since c.Activity__c does not exist for me. Here some pseudo code to represent what I need:
trigger TaskChanges on Task (after update) {
for (Task t :System.Trigger.new) {
parentCase.LastModifiedDateActivity__c = Date.Today();
}
}
Since all activities in the internal ActivityHistory object (email, phone calls, etc.) will be handled in the same way, an if clause for the type of activity is not necessary. All activities should update the parent case's LastModifiedDateActivity__c field with the Today() / Now() functions so that we can track the newest activity within a case.
How can I modify the above pseudo code to actually identify the parent case and update it's LastModifiedDateActivity__c field? Also, you mentioned I should create a test class and debug it within an SF sandbox. Is the class necessary for this to function or was that just meant for test purposes? I am trying to find the smallest, easiest and most efficient solution for this issue since this will be my first piece of Apex code and overly complex scripts/solutions will dilute my understanding of what the code is actually doing.
trigger TaskChanges on Task (after update) {
parentCase.LastModifiedDateActivity__c = Date.Today();
}
Going up and modifying the parent of a Case is a little difficult because it's polymorphic -- it can be either a Case, a Contact, or Activity. So I don't think you can use a nested query to get to the value; If anyone knows a better way to to this - please post it - as it's kind of a hack. I think this code will allow you to do what you want; But it is untested -
It only tests for modified child cases that have a parent -- I think that's your use case....
Oh - I forgot to mention -- if a child case is also a parent of another child, and both are being ipdated (like in a bulk load) it will throw an error. So there should also be a before insert trigger that makes sure that case doesn't happen. - or, I guess you could just insert a throw-catch to catch any error that pops up.
I have the exact same need to have a date/time field update with the latest activity on a case. Except I have little experience with APEX triggers or classses.
I was hoping you could share the code you ended up going with and perhaps a tip or two on creating the trigger/class?
It would be very much appreciated.
Regards,
Liam