---
schema_version: "1"
id: 17ac9e4c35dfc19800f765130ccd61b01f0560ede0328cd0f9da5e3847e14a62
title: Dynamic Visualforce Bindings
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/dynamic-vf/pages-dynamic-vf.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-dynamic-vf.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: ec93f9ba4173d9131554ba543c624e667922b86097bffc01015efc20319c1681
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Dynamic Visualforce Bindings

Dynamic Visualforce bindings are a way of writing generic Visualforce pages that display information about records without necessarily knowing which fields to show. In other words, fields on the page are determined at run time, rather than compile time. This allows a developer to design a single page that renders differently for various audiences, based on their permissions or preferences. Dynamic bindings are useful for Visualforce pages included in managed packages since they allow for the presentation of data specific to each subscriber with very little coding.

Dynamic Visualforce binding is supported for standard and custom objects. Dynamic bindings take the following general form:

```visualforce
reference[expression]
```

where

-   _reference_ evaluates to either an sObject, an Apex class, or a global variable
-   _expression_ evaluates to a string that is the name of a field, or a related object. If a related object is returned, it can be used to recursively select fields or further related objects.

Dynamic bindings can be used anywhere formula expressions are valid. Use them on a page like this:

```visualforce
{!reference[expression]}
```

Optionally, you can add a _fieldname_ to the end of the whole dynamic expression. If the dynamic expression resolves to an sObject, the _fieldname_ refers to a specific field on that object. If your `reference` is an Apex class, the field must be `public` or `global`. For example:

```visualforce
{!myContact['Account'][fieldname]}
```

Your dynamic Visualforce pages should be designed to use a standard controller for the object on your page, and implement any further customization through [a controller extension](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/controller/pages-controller-extension.md#building-a-controller-extension).

You can use the Apex `Schema.SobjectType` methods to get information for your dynamic references, in particular those that access the fields of an object. For example, `Schema.SobjectType.Account.fields.getMap()` returns a Map of the names of the Account fields in a format that your Apex controllers and extensions can understand.

**important:** Static references are checked for validity when you save a page, and an invalid reference will prevent you from saving it. Dynamic references, by their nature, can only be checked at run time, and if your page contains a dynamic reference that is invalid when the page is viewed, the page fails. It’s possible to create references to custom fields or global variables which are valid, but if that field or global value is later deleted, the page will fail when it is next viewed.

## Defining Relationships

Both `reference` and `expression` can be complex expressions, such as those that evaluate to object relationships. For example, suppose that an object called Object1__c has a relationship to another object called Object2__c. The name of the relationship between these two objects is called Relationship__r.

If Object2__c has a field called `myField`, then the following dynamically-cast lookups all return a reference to the same field:

-   Object1__c.Object2__c['myField']
-   Object1__c['Object2__c.myField']
-   Object1__c['Object2__c']['myField']
-   Object1__c.Relationship__r[myField]
-   Object1__c[Relationship__r.myField]
-   Object1__c[Relationship__r][myField]

**See Also**  


-   [Dynamic References to Global Variables](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-dynamic-vf-globals.md)
-   [Global Variables](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/variables/pages-variables-global.md)

