3

I'm finding myself use 'special objects' from time to time (e.g. an account to gather spam contacts), and I find myself wanting to refer to this object in apex code, JavaScript buttons etc. I'd rather not hard-code the name everywhere, in case someone will (want to) change it.

I thought to add a 'Custom Setting' but that cannot refer to objects. Is there anything that can? One approach I've thought about is to make a special object type, make it a singleton (using a 'unique' field) and put my setting there as a custom field.

Are there better ways to do this?

2 Answers 2

4

The singleton object 'Environment_Values__c' (not a custom setting) has certain appeal:

  1. You can manipulate the layout using page layouts
  2. You can code validation rules (this can avoid system failures when env parms aren't set up correctly)
  3. You can use lookup fields such as in your use case: 'spam_account__c' - this improves transparency
  4. You have access to Reports, Workflows (admittedly a limited use case)

The downsides are:

  1. Burns up a SOQL call when referenced (as opposed to the Custom Setting solution proposed by @guy)
  2. Each new 'parameter' is likely to become a new custom field so there will be metadata deployment issues (as opposed to a Custom Setting that is simply a keyword: value data model
2
  • An additional thing I'm hoping for (but haven't actually tried) if someone tries to delete that referred object, there will be a warning about it being in use/referred/...
    – Legolas
    Jun 26, 2014 at 13:39
  • And good point about the SOQL call, I hadn't considered that.
    – Legolas
    Jun 26, 2014 at 13:40
5

What I've done is create a custom setting and put the record Id of the special object record in a text field in the custom setting.

Retrieving the custom setting is easy and fast, as it's in the cache.

The Id is unique and is the fastest way (in terms of performance) to query the special object record for additional field data.

You must log in to answer this question.

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