You need to sign in to do that
Don't have an account?

How do I reference a custom field in an unrelated object within a trigger?
Hello - I am trying to figure out how to set a custom field value that resides within the Activity object to the value of Task.ActivityDate. I am not sure how to reference the custom field (Activity.Activity_Due_Date__c) properly in my for loop below.
trigger GetUsableTaskDueDate on Task (before insert, before update) {
trigger GetUsableTaskDueDate on Task (before insert, before update) {
Task[] checkTasks = Trigger.new;
for(Task t : checkTasks){
Activity.Activity_Due_Date__c = t.ActivityDate;
}
}
This is my 4th day learning SF and my first real task. I am a 12 year veteran web app developer and this task seems like it should be trivial.
This is my 4th day learning SF and my first real task. I am a 12 year veteran web app developer and this task seems like it should be trivial.
All suggestions are appreciated.
Thanks!
Actually.... I believe Activities are really just Tasks. Are you trying to set the field of your current task, since it could also be an activity? So are you essentially trying to take 1 field and copy it to another?
All Answers
As far as I know there is no object called Activity, there is Event and Task. Are you trying to set the value of a custom field in Event? You can do this by querying the Event object, but in my opinion you should have some criteria to select which event record you want to update based on the task record in the trigger.
Let me know and I can help you update this code.
Where are you getting this Activity from?
I'm not quite sure what you are trying to do. A more specific use case might be helpful. Are you trying to create a new Activity from a Task? If so something like...
Actually.... I believe Activities are really just Tasks. Are you trying to set the field of your current task, since it could also be an activity? So are you essentially trying to take 1 field and copy it to another?
Hey Damien_,
Thank you for your replies. You are spot on, I just got it to work and have exactly what you wrote.
So when you say "I believe Activities are really just Tasks" - what does that mean? I checked for a relationship between the objects but was unable to find anything documented..
Thanks again.
In your Salesforce Instance
Setup -> customize -> Activities
Tasks/events/activities are all under this.
If you add a field to the Activity Custom fields here, then go look at your Schema in Eclipse. Look up Tasks, and you will see the new field there. There is no Activity Table in the database, only Task. (You will need to make sure you refresh it after adding the custom fields.)
Thanks again. How do I view my Schema through Eclipse? I can see the Schema through the Admin, but the custom field resides in the Activity Object. Here's a screen shot..
![]()
There is no Activity object. The Custom field actually gets added to the Task object. Under your probject in Eclipse, you will see Salesforce.schema. Just double click that file.
Ok - thanks for the tip. I can see Activity_Due_Date__c in the Task object looking at the schema through Eclipse. And it looks like all the "Activity" fields are in there as well. Why would "Activity" show up, as what "looks" like as a separate object in the Schema Builder through the application? I was hoping to show you a screen shot of what I see but Im having issues getting it loaded. Looking through the forum Help to see what Im doing wrong now..
Here is what is confusing me in the Schema Builder..It shows the Activity Due Date (Activity_Due_Date__c) under "Activity"...
Just think of them as a single object, which Activity extends Task. So an Activity is actually a Task, but a Task isn't necessarily an activity.
Thanks again for your response. Did you just try to use a Jedi mind trick on me? :) To me if the custom fields are task related, they should show up under the Task Object in the Schema Builder. Not under an object that doesn't exist. Anyway, I get what you are saying, I will use Eclipse going forward for my schema viewing needs.