+ Start a Discussion

Trigger to update custom task field

I have two custom objects:

object1__c is a list of offices
object2__c is a list of employees, and each record on this object is related to object1__c through a lookup relationship field.

When an activity is logged against either of those objects, I want to update a custom field (related__c) on the task object that will include the office name from object1__c.  I'd assumed this would be relatively easy to do via the relationship between the two, but I'm stuck.  

I've been able to accomplish this through the use of two seperate simple field update triggers, but it seems to me there has to be a way to do it with one.  Can anyone provide any guidance?

I am looking to do this such that I can report on all activities that are in any way related to the office, whether they be logged against the office itself or one of the employees of that office.  From what I can tell, you can report on "activites with object1" or "activities with object2," but not both in a way that they can easily be grouped together.

Hi pjs,

Why don't you create a custom object that holds the same functionalities as Activities with similar fields and all. This custom object will have a lookup relation to your office object and Employee object. If an activity cannot have employee and office together then you can put in a validation rule for that object so that business users do not make that mistake. In this way, all the information are stored in one object and you can run the report on that object.

Hope that helped!

Justin - thanks for your reply.  But while that solves my reporting problem, I then lose the ability to create follow-up tasks when logging a call, for example, right?  While I suppose it'd be possible to replicate that to an extent, it would seem the effort involved would be at least as great as trying to figure out the trigger.
pjs, you can create task and log a call on that custom object as well. 
If you want the ability to report on activities for employees and office at the same time then this is the best option. For now, try to create a custom object similar to activities, and in that you need to make sure that you check the checkboxes, allow reporting and Track activities.