1

If I have a custom list setting, 'Info_List__c' with 1 field, 'Info_Field__c'.

What would a method look like that would iterate through the list and return all entries.

And how would I call that method from a VF page and store the results in a JS object?

1 Answer 1

2

This controller property will provide a JSON string of all the list custom setting entries:

public String infoListJson {
    get {
        return JSON.serializePretty(Info_List__c.getAll().values());
    }
}

and that JSON can be picked up in the Visualforce like this:

<script>
...
var infoListJson = {!infoListJson};
...
</script>

Or if you just want to return the Info_Field__c values and not the other fields of the list custom setting:

public String infoListJson {
    get {
        String[] infoFields = new String[] {};
        for (Info_List__c item : Info_List__c.getAll().values()) {
            infoFields.add(item.Info_Field__c);
        }
        return JSON.serializePretty(infoFields);
    }
}
2
  • Thanks Keith but I'm getting this error: Save error: Variable does not exist: Info_List__c
    – Daft
    Commented May 20, 2014 at 10:59
  • 1
    @Daft That needs to be the "API Name" of your list custom setting. Check that it is.
    – Keith C
    Commented May 20, 2014 at 11:01

You must log in to answer this question.

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