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?

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);
    }
}
  • Thanks Keith but I'm getting this error: Save error: Variable does not exist: Info_List__c – Daft May 20 '14 at 10:59
  • 1
    @Daft That needs to be the "API Name" of your list custom setting. Check that it is. – Keith C May 20 '14 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.