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
HL-DevHL-Dev 

Efficient way to query a custom field from the User table

Hi,
 
I'm trying to think of an efficient way to pull the value of a custom field (Cost_Center__c) within the User table. Here's my situation: I'm given a set of Event records and using their OwnerId's, I'm trying to think what'd be an optimal way to pull the user's cost center. My requirement is that I read the currently logged in user's cost center, and given the set of event records, only pull the events with users (the user which the event is assigned to) that have a matching cost center.
 
I know I could get all the OwnerId's from the Event records and use them to query the user table to find the matching pair, but then I'd be making one API call/comparison, which isn't optimal at all. Also, I could probably add a new field on the Event record that calls an Apex Trigger (after insert) that would check the event's OwnerId, lookup the user table and write the cost center over to this new field.
 
Is there something else I could do to achieve my goal?
 
Thanks in advance.


Message Edited by HL-Dev on 09-11-2008 09:21 AM
Best Answer chosen by Admin (Salesforce Developers) 
HL-DevHL-Dev

I decided to go with the Apex class and trigger aproach. Just updating this post to avoid unnecessary replies :-)