4

I am trying to decide whether to use Text or AutoNumber for the detail object in master-detail relationship.

What are the considerations that may affect this decision?

2

Totally depends on what you are trying to do with the detail object. Unless you are using it as purely an attribute storage object, such as yearly company profiles (revenue, employees, etc), I recommend using Text.

The "Name" field gets special treatment by salesforce in that it is automatically indexed, searched upon, and shows up in lookup fields. I personally don't like seeing "X0001958" in the lookup field, since it gives me no clarity as to what it is. The indexing/searching is also a huge benefit since whatever you throw into the Name field is searchable by default.

If your goal is to decrease the number of fields needed for input (say, a date field and a revenue field) then perhaps consider setting Name using a workflow rule that might combine the Parent Name + Date or something along those lines...

Also, another downside to auto-numbers is that they are not always consistent. When you have test classes testing triggers on that object, they will advance the auto-number generator artificially, so you'll get gaps in your number increments.

2
  • 2
    Nathan -- note that in Spring14, Develop | Apex Test Execution | Options..., selecting Independent Auto-Number Sequence allows one to mostly avoid the gaps in auto-number fields when running tests
    – cropredy
    Apr 24 '14 at 0:42
  • Ah! I hadn't seen that yet. Great to know! THanks @crop1645 Apr 24 '14 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.