Custom Settings Fun

Custom Settings are one of the great ways a developer can give admins power to update logic, settings, and the behaviour of code and really make code more flexible.

This is just a quick reference of all the cool ways you can pull those settings back out without having to use a SOQL statement.

// Method that loads all records in to a list:
list<Customer_Setting_Name__c> buList = Customer_Setting_Name__c.getall().values();

// Method that loads a specific record using the name as a filter:
Customer_Setting_Name__c aplo = Customer_Setting_Name__c.getValues(filter_string); // filter_string is just a string passed in

// Method loads all records in to a map with the name as the key:
Map<String,Customer_Setting_Name__c> buMap = Customer_Setting_Name__c.getAll();

The great thing is that these do not take a SOQL hit and admin can update these.

Some of the uses I use this for:

  • Mapping Business Unit settings for Lead Queue’s, record types, groups, etc.
  • Multi-dimensional Pick lists that need to shared across objects, enabled/disabled (Global Picklists have taken the place of a lot of these), and that require additional attributes but maybe don’t warrant the need for a full custom object IE security.
  • For ‘quick disable’ functionality for when I want to put code in production that might need to be quickly disabled

Leave a Reply

Your email address will not be published. Required fields are marked *