2

I have a need to set a field, Account.Previous_Owner_Id__c, which will store the 18 characters Id of the User who used to be the previous owner of the account.

Questions:

  1. If we create this field as a lookup field to reference the User object, is there any overhead added to the system? For example, having an additional lookup field makes the SOQL queries longer to load even when the field isn't referenced in the SELECT portion of the query.
  2. Would it be better to just use a 18 character Id field as a text field?

1 Answer 1

2

If we create this field as a lookup field to reference the User object, is there any overhead added to the system? For example, having an additional lookup field makes the SOQL queries longer to load even when the field isn't referenced in the SELECT portion of the query.

There are some costs in the backend, but for a single field, these costs are insignificant for the benefits you get; the ability to get field data from the related objects in reports, queries, the ability for Salesforce to validate the ID values as existing records, being able to display the name of the record when you put the field on a page layout and reports, etc.

Would it be better to just use a 18 character Id field as a text field?

This almost always ends up not being worth the trouble. I'd avoid doing this if you can help it.

3
  • 2
    Totally agree - if you have an ID value store it in a Lookup for all those serious advantages. Nice answer.
    – Phil W
    Commented Dec 16, 2021 at 20:16
  • 4
    There should be a very strong preference for lookup anywhere it is viable. Mostly I only use text to hack in polymorphism.
    – Adrian Larson
    Commented Dec 16, 2021 at 20:18
  • although not directly applicable to the User object, storing IDs as strings means that if the referenced object is deleted or merged (hence, deleted), you won't have broken references
    – cropredy
    Commented Dec 16, 2021 at 23:10

You must log in to answer this question.

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