Dear awesome readers,

If you have already played with sObjects and Visualforce, you have surely gone through the below link. If you havn’t please do. Its simple and sets the tone for the revelation in this post.

The developer guide talks precisely what we need to display an sObject on VF. i.e. :

While in apex we do:

sobject s1 = Account.sObjectType().getDescribe().newSobject();
s1.put('name','awesome reader');

In visualforce we will do the following:

<apex:inputField value="s1['name']"/>

Now, what happens if we are to deal with an sObject List? Lets experiment:

In apex:

List<sobject> s1 = new List<sobject>();
sobject s1[0] = Account.sObjectType().getDescribe().newSobject();

works well!

In visualforce the following makes logical sense:

<apex:inputField value="s1[0]['name']"/>

However it throws a compilation error!!!

hmmm… So what is the right way? While there are many my personal favorite is to use apex:repeat in the following manner:

<apex:repeat value="s1" var="sobj">
  <apex:inputField value="sobj['name']"/>

Eureka!! It works!