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
Nalec7Nalec7 

Apex Code? Days Since Last Activity Type

I have a custom contact field called Days Since Last Activity - Today()- LastActivityDate. However, the new business requirement is to only calculate Days Since Last Outgoing Call Types. The activity picklist values are Outgoing Email, Outgoing Call, Outgoing -  Call Hit

In Summer '14, you can access activity dates in formulas however you can not access activity/task types. I also tried workflows, no luck.

My understanding now is this must be done with a apex trigger. It would evaluate the Call type field and update the Custom field if the criteria is met. Does anyone any simular code that can be used?

Thanks, Chris
KevinPKevinP
Chris,

The basic idea here, is to generate a single query, which when run, returns the date of the last outgoing call. 

This is a particularlly tricky bit, because the tasks and events fields are polymorphic in Salesforce. Yay. 

Here's a helpful diagram: https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_activities.htm

this is the start of a query.

Select CallType, LastModifiedDate from Task WHERE callType = 'Outbound Call' AND whatId = :YourAccountID Order By LastModifiedDate ASC LIMIT 1;


Nalec7Nalec7
Kevin - Thanks for the reply. Let me review and figure out where to go next with this. If you could suggest anything else, it would be greatly appreciated. Cheers.