I familiar with custom object but what about custom setting?
[SalesForce] difference between custom setting and custom object
Related Solutions
A few things to take into consideration:
- Are you accessing from a test method - If so you must insert a custom setting first
- Is there a record for the Specified "Instance" for the current context user?
If no custom setting for the current user is defined then it returns a new custom setting and the ID will be blank. Otherwise the getInstance() should return the ID:
CustomSettingExample__c cs = CustomSettingExample__c.getInstance();
//cd.id - should NOT be null if a custom setting exists for the current context user.
If no custom setting data is defined for the user, this method returns a new custom setting object. The new custom setting object contains an ID set to null and merged fields from higher in the hierarchy. You can add this new custom setting record for the user by using insert or upsert. If no custom setting data is defined in the hierarchy, the returned custom setting has empty fields, except for the SetupOwnerId field which contains the user ID.
If you need more detailed answer then you may be better served by posting your code so we can tell if it is a problem with your code or not.
No, you cannot create a relationship from a Standard Object
or a Custom Object
to a Custom 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:
All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. This data can then be used by formula fields, validation rules, flows, Apex, and the SOAP API.
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.
Best Answer
Custom settings is an standard object of the salesforce platform, where you can save your settings and associate it to the profile or user.
Here is some info from the official doc:
Generally you can use custom settings for the parameter that can not be stored in the profile or user object. For example "Google Maps Key" for all profiles or whole org. Or region for the specific profile.
Learn more bout Custom Setting here.
Information about how to access Custom setting.