2

My package has a CustomSetting object that contains all the configuration values needed to power my application. I would like to add a field that contains all "open" lead statuses, configurable by the installer, which I can then use in a formula field to see if a lead is "open" or not (as opposed to rejected, inactive, converted, etc).

Unfortunately there isn't any way to create a field for a CustomSetting object that contains several values. The best way I can think of is just to have the installer enter comma-separated list of statuses, store that as a string, and then in formulas, use:

CONTAINS($Setup.MyAppSettings__c.OpenStatuses__c, Status)

Is this the best way to do this? Am I thinking about this wrong?

Thanks for your help!

3 Answers 3

0

Yes, you are on the right way. For example i am doin it the same way: comma separated string of values: val1,val2,val3. And then in apex just do split to get a list with all values:

List<String> vals = setting.split(',');

Or checking whether the setting contains any value:

Boolean isSet = setting.contains('val1');
0

If you define an additional Custom Setting object as a "list" type rather than "hierarchy", then you can create multiple records in that object, each one of which will be one of your Status values. this will be more intuitive for the Admin to use, since each status is a separate Custom Setting record.

This only really works if you only have one bunch of application settings per Salesforce Org. It becomes more complicated if you have, for example, two records in your existing Custom Setting object.

1
  • Thanks for the idea; the reason why I stayed away from "list" type is that I couldn't use it in field formulas...
    – Chung Wu
    Commented Aug 26, 2013 at 20:10
0

Since I still wanted to do the "is an open status" check from a formula field instead of apex code, I couldn't use mast0r's solution.

Instead, I ended up having a VF page for editing MyAppSettings_c anyway, so I added some logic to my controller when saving the OpenStatuses_c field:

// Special property for open statuses on the controller; this is referenced
// from VF as an apex:inputTextarea
public String statuses {get; set;}

// On saving, add start/end markers to each status
List<String> lines = statuses.split('\n');
List<String> results = new List<String>();
for (String line : lines) {
  if (!String.isBlank(line)) {
    results.add('$$myapp_start$$' + line.trim() + '$$myapp_end$$');
  }
}
settings.OpenStatuses__c = String.join(results, '\n');

// on loading / displaying, remove the start/end markers
statuses = settings.OpenStatuses__c.replace('$$myapp_start$$', '').replace('$$myapp_end$$', '');

Now, from my field formulas for Lead, I can just do:

CONTAINS($Setup.MyAppSettings__c.OpenStatuses__c, '$$myapp_start$$' + TEXT(Status) + '$$myapp_end$$')

The start / end markers are there to ensure that I always match on the whole status string, and never just a substring of a status listed in OpenStatuses__c.

Yes, this means that if my user goes to Settings | Develop | Custom Settings | Manage, they'll see some weird string markers in some fields. But if my user always goes through my VF page to edit the settings, everything should be fine.

You must log in to answer this question.

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