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
RatherGeekyRatherGeeky 

Populate Custom Task field with Custom User Field - Trigger Help for Newbie

I am very new to writing triggers. I've been reading the cookbook and scouring the community for similar newbie posts. I know this is a simple concept, but I'm unsure of how to proceed. Any guidance would be appreciated.

What I Want to Do: Populate a custom field on the Task object with a custom picklist value on the User object. (If a lookup to the user object was possible, this would solve all my problems!)

My Method: So far, this is what I've got. Pretty pathetic. 

I created a class like this:

 

public class DetermineUserRegion { // This class should automatically set the Region field to the assigned user's region User currentUserRegion = [Select region__c From User Where User.Id = Task.OwnerId ]; Task.User_Region__c = currentUserRegion; }

And then I was going to call that from the trigger. 

But, no success as of yet. Perhaps that isn't even the best method.

Any advice for a newbie?

 

Ron929Ron929

You should just do this all in a trigger.

 

something like

trigger trgUserRegion on Task (before insert) {
String URegion = [select subject from USER where id = {!USER.ID} LIMIT 1].region;
System.debug('URegion : ' + URegion );

FOR  (Task act:System.Trigger.new) {                                    //identify field on task for user region                             System.debug('act region:' +act.region);                                                          act.region = {!USER.region};   }

 

 

I am also new to this, so this may not be exact, but I believe you can do it all in the trigger easier than writting a separate class.  You also may be able to utilize workflow rules even easier.

 

Message Edited by Ron929 on 03-10-2009 12:51 PM
RatherGeekyRatherGeeky

Ron929:

 

Thanks for your reply. I'll test it out!