Newer Version Available

This content describes an older version of this product. View Latest

Reference Apex Maps and Lists

Visualforce pages that use dynamic bindings can reference the Apex Map and List data types in their markup.
For example, if an Apex List is defined as:
You can access the list values in a Visualforce page using {!object} syntax and array notation.
Similarly, if you have this Apex Map:
You can access the map’s keys and values in a Visualforce page using {!object} syntax and array notation.

Use dynamic references to lists and maps in an <apex:inputText> tag to create forms using data that isn’t in your organization’s custom objects. Working with a single map can be much simpler than creating a series of instance variables in an Apex controller or creating a custom object just for the form data.

Here’s a Visualforce page that uses a map to hold form data for processing by a custom controller.
And here’s a simple controller that works with the form.
A Map can contain references to sObjects or sObject fields. To update those items, reference a field name in the input field.

Unresolved Dynamic References

Keep in mind the following issues that can arise at run time if a dynamic reference doesn’t resolve:

  • If there isn’t a value mapped to a particular key or the value is null, the Visualforce page returns an error message. For example, with this controller:
    This page causes an error at run time.
  • If the key is null, the Visualforce page renders an empty string. For example, using the same controller as above, this page shows an empty space.