Once I had the illusion that accessing custom setting is always free and does not consume any governor limits. Until today: I've learned the hard way that this is only half-true.
It is true, that this comes without the cost of a query:
But this DOES cost you a query
database.query('select Id from MyCustomSetting__c ');
Now how can I get the setting dynamically in a way that my code runs on every org regardless of the existence of
MyCustomSetting__c? I need to hide the setting from Salesforce so that I can use something inside of a try/catch. If the setting does exist I need to get some values. If it does not exist I fall back on default values.
Additionally I need a way to update records of the settings synchronously in trigger contexts.
- Can this be done free of charge of any query limit?
- Where is the documentation that using database.query() for CustomSetting cost limits? I can not find it. If there is no documentation, I would assume that either the documentation is wrong or incomplete OR the limit consumption is a BUG.
I've tried to use
CustomMetadataType instead. It failed.
CustomMetadataType (CMT) is similar to
CustomSetting (CS) and CMT looked very promising at the first glance. I watched this video from 2019 where CMT is advertised as more powerful successor of CS. Especially this slide convinced me to give them a shot:
BUT in fact CMT is unusable for me, because it does not support DML to update records. Records can be updated asynchronously with APEX. Not sure if this works in trigger context, but the possible timing issues are not acceptable for my requirements. I need updates of records in sync.
So I would not agree that CMT is on par with CS in all aspects. DML and in sync updates are crucial for some scenarios.