function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tanmay SahaiTanmay Sahai 

Change account ownership based upon Last Activity Date

Hi All,

I am looking to automatically change the account ownership to a default user when the last activity date by the current account owner exceeds 30 days.
I am using a default System feild : Last Activity Date but it gives the last activity of the Account user instead of the Account owner. Do I need a separate trigger to update this field and then use this field value in another trigger.

Can somebody help me with the trigger??

Thanks in advance!
Narender Singh(Nads)Narender Singh(Nads)
Hi Tanmay,

Use LastViewedDate or LastModifiedDate in your trigger (whichever suits your requirement better).

LastActivityDate Description:
Value is one of the following, whichever is the most recent:
1. Due date of the most recent event logged against the record.
2. Due date of the most recently closed task associated with the record.

Let me know if it helps
Thanks!

 
Tanmay SahaiTanmay Sahai
Hi Narender,

Thanks for your response!

I was curious to know that won't the LastModifiedDate count for any chnages made on the Account irespective of whether it is for Activity or for any modification/updates. I guess I should take LastViewedDate into consideration to write my trigger.

So, how to get the LastViewedDate?

Thanks!
Narender Singh(Nads)Narender Singh(Nads)
Can you please clarify, by Activity you mean the Activity sOject ?

So, how to get the LastViewedDate?
LastViewedDate is a standard date type field on Account object. You can simply refernce it in your code like you do for other fields.
Like:
Account a=[select LastViewedDate from account limit 1];
system.debug(a.LastViewedDate);
 
Tanmay SahaiTanmay Sahai
Yes, by Activity I meant Activity sObject. I am using the standard Salesforce System field : LastActivityDate as a formula field on the Account object. I guess I just need to reference this field in my trigger.

Thanks for the response!