Monday, February 21, 2011

User friendly object lookups in Force.com

The typical approach to user lookups and searches in form development would be to:
  • fetch a list of object IDs and descriptions
  • display the descriptions to the user and allow them to select
  • return the ID(s)
This is tricky in Force.com because there is one standard object identifier field that is always used for lookups and searches. You can make this field an ID for referential integrity purposes, or you can make it a text field for user readability - but you can't do both.

Another ugliness is that the identifier field can't be removed from the object creation page and is editable by default.

A workaround is as follows:
  • In the object page layout, move the identifier field to the system information section. This shifts it out of the way a bit.
  • Create a custom button that puts a default value into the identifier field
  • Add a workflow rule to copy a value into the identifier field from another field