Why I can't create relationship between custom object and custom setting. When try to create lookup field in my custom object, custom settings are not listed in available objects.
[SalesForce] Create relationship between custom object and custom setting
Related Solutions
There are only technically two types of relationships between objects in Salesforce, master-detail and lookup. Though in reality when coding and in the UI you'll find both have some common behaviours and ways in which they can be used.
So Salesforce does not technically require you to do anything different regardless if your lookup references another object or itself, both are the same field type, lookup. So the difference is more the use case your using the field for than it's type. Note that the Standard object Account uses self references to implement Account hierarchies, parent and child relationship.
This topic in the documentation Relationships Among Objects is a good place to start reading more, and i noticed also covers a cool use case of master-detail relationships relating to many-to-many relationships. Hopefully this sheds a bit more light on the topic for you, but if you need more feel free to explain a little more in your question about your use case.
Extract from the above linked help topic...
Relationships associate objects with other objects. For example, a relationship can link a custom object to standard object in a related list, such as linking a custom object called Bugs to cases to track product defects associated with customer cases. To view the parent and child relationships among standard objects, see the ERD diagrams in Data Model.
There are four different kind of relationships in the force.com platform.
But I like to categorize them in a slightly different way than the help pages:
- Lookup
- Master-Detail
- Hierarchy
- Standard relationships
There are lot's of help topics and articles on Lookup and Master-Detail, such as the relationship overview and the relationship considerations topics in help. I don't like including Many-to-Many in this kind of discussion because, for all intents and purposes M:M is just an implementation of two M-D relationships (by strict reading of the docs), or possibly two lookup relationships or a mix of the two.
To dispense quickly with hierarchy relationships, these are a special lookup self-join relationship on the User object. Read up on those on your own. :-)
So let me talk about my own invented fourth category.
Standard Relationships
If we (salesforce.com) provide you with a relationship between two objects, that is a standard relationship. Not lookup, not master-detail. Why do I bother providing this fourth category? Because it is the easiest way to stop people trying to categorize them as either lookup or master-detail when they often share characteristics of both. When you approach working with any standard relationship the question you really need to answer is, "how does this standard relationship behave." Frequently standard relationships have characteristics that you just can't do with a custom relationship. Ever tried to make a custom relationship polymorphic? Go ahead...give it a try. You will fail. But there are many examples of polymorphic standard relationships.
I like to categorize these in their own separate place independent of lookup/master-detail. In fact, anything standard follows the same rule: it behaves exactly the way that salesforce.com wants it to behave to fit the particular purpose of that standard thing.
In my opinion, the Account-Contact relationship is a perfect justification for this fourth category: it is a little like lookup, a little like Master-Detail, but fundamentally behaves the way it does because we decided it should.
That might not be the "proper" way, as you ask, but it is the one that makes the most sense to me.
Best Answer
No, you cannot create a relationship from a
Standard Object
or aCustom Object
to aCustom Setting
(nor the other way around).As for why, the simple answer is that it is a platform limit. They were designed with this limitation in place, and it is a constraint you have to keep in mind when selecting
Custom Settings
as part of your solution.From a technical perspective, I imagine part of the reasoning was to help the cloud architecture Salesforce has put in place scale to billions of transactions per day. As you may know,
Custom Settings
are stored in the application cache:Injecting data dependencies to or from this layer of the application would increase the technical complexity of implementing that caching mechanism, at the very least, if not make it impossible.