function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SurekaSureka 

Issue in rendering a field set dynamically

Hi,

 

I have the following code inside the repeat variable in the VF page:

<apex:repeat value="{!qa.getFieldsSetMemb}" var="ff" >         
<apex:outputField value="{!acc[ff.fieldPath]}"/>
</apex:repeat>

 where "qa.getFieldsSetMemb" returns "List<Schema.FieldSetMember>" 

acc is the name of the account variable.

 

I am trying to dynamically display a field set in the above code.

 

While saving the VF page, I m getting the following error:

 



 

Error: java.lang.NullPointerException

Error: null



Any Idea?

 

Thanks

Bhuvana

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

<apex:page standardController="Account">

 

 

<apex:repeat value="{!$ObjectType.Account.FieldSets.a}" var="f">

 

{!$ObjectType.Account.Fields[f].label}

 

<apex:outputField value="{!Account[f]}"/>

<br/>

</apex:repeat>

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

SurekaSureka

Hi,

 

Please note that I am dynamically getting the field sets from the class. The following code hardcodes the field set name.

 

<apex:repeat value="{!$ObjectType.Account.FieldSets.a}" var="f">

 

{!$ObjectType.Account.Fields[f].label}

 

<apex:outputField value="{!Account[f]}"/>

 

Thanks

Bhuvana

Platy ITPlaty IT

Good to know that you can get field sets in apex, I didn't know that. I suspect the issue is related to returning that field set from the controller/extension. Either it's not getting a field set, or maybe it's a timing issue that the page is loading and then those variables are being populated.  Try pulling {!qa.getFieldsSetMemb} out of the repeat and displaying it right on the page just to see what's being returned.  And if that's not it, do the same with {!ff.fieldPath}- display it inside of the repeat without the outputField.  That should help you at least troubleshoot exactly where the issue is.

 

aballardaballard

What does the controller code look like? 

(Though if you are getting this error when you try to save the page definition, sounds like a bug...)

harsha__charsha__c

it means that the {!qa.getFieldsSetMemb} list is empty.....

                     make sure that the list contains the fields...(by a debug statement)

 

Make sure your controller code contain  :

 

public List<Schema.FieldSetMember> getQa() 
{
     return SObjectType.Merchandise__c.FieldSets.Dimensions.getFields();
}

 And in the page mark-up no need for  qa.getFieldsSetMemb, if you have the above code in your controller...just {!qa} is enough

 

if it takes you to the solution, mark it as solution....

harsha__charsha__c
 <apex:pageBlockTable value="{!mapStudent}" var="st" id="Table"> 
<apex:repeat value="{!$ObjectType['sObject Name'].FieldSets['fieldset name']}" var="f"> <apex:outputText> {!mapStudent[st][f]} </apex:outputText> </apex:repeat>

 mapStudent : The map which stores all the records of the sObject.

 

map<string, sObject>

 

If this gives you solution , mark it as a solution

rajesh k 10rajesh k 10
Hi harsha,
I have one requirement,
Actually using below code i save object record in database dynamically.
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objectName);
SObject myObj = targetType.newSObject();
insert myObj;

Note:using above code related object record only created.ButFields information is not saved.Here Fields add visualforce page Dynamically

but I gave some fields information here but those fields information is not saved in this record
How to save fields information also related object record Dynamically?

help me...............