I have a custom object with Activities enabled, as such it has the child relationship ActivityHistories - I wanted to show a count() of the related Activities associated w/ each object of a certain type:

COUNT(WHERE ActivityHistory.Type = 'Call')

Is this possible in a Formula Field? I don't see any merge fields for it, and I can't create a Roll-Up Summary (inactive the field editor UI, so I assume it's not available that way?)

Or do I have to write a custom trigger and update it when the Task is inserted?

  • I reckon best bet would be 2 roll-up summaries on Tasks and Events (completed/closed) and then a formula field to sum the two roll-up summaries. Commented Jul 17, 2015 at 1:44
  • @Bachovski still ActivityHistories is not an available merge field for formula's on my custom object? Commented Jul 17, 2015 at 6:49
  • ActivityHistories represent either a Task or an Event that is completed. So your roll up summary would be on both task and event objects. In your formula you'll sum both roll up summary fields Commented Jul 17, 2015 at 8:23
  • I dont think we can create roll up summaries in this case. Commented Jul 17, 2015 at 8:39

1 Answer 1


You will have to write an Apex Trigger. The trigger should fire and work on multiple events, like

insert - if a closed activity (even or task is inserted)(+count)
update - if open activity is closed (+count) if closed activity is opened(-count)
delete - if closed activity is deleted (-count)
undelete - if a deleted closed activity is restored.

Let me guide you to a link that can help you to write this trigger. This link calculated count for OpenActivities, all you have to do is apply your logics and count for ActivityHistory.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .