You need to sign in to do that
Don't have an account?
Dynamically call Field Set on VF Page
I'm currently been playing around with field sets (which I love btw).
I'm hoping I can create a page that has a dynamic call to a field set and then display those fields.
I was thinking I could put the string to reference the field set in a list of the controller and then call that on the page through an apex:repeat.
So my Controller would look like:
public class My_Ext { public list<String> csNames {get;set;} public My_Ext(){ csNames = new list<string>(); csNames.add("$ObjectType.Case.FieldSets.MyFieldSet1"); csNames.add("$ObjectType.Case.FieldSets.MyFieldSet2"); csNames.add("$ObjectType.Case.FieldSets.MyFieldSet3"); } }
and the page would be like this:
<apex:page controller="My_Ext" > <apex:pageblock title="All my Field Sets in Sections"> <apex:repeat value="{!csNames}" var="cs"> <apex:pageblocksection title="A field set" columns="2"> <apex:repeat value="{!cs}" var="f"> <apex:outputfield value="{!Case[f]}" /> </apex:repeat> </apex:pageblocksection> </apex:repeat> </apex:pageblock> </apex:page>
To make it a bit more dynamic I would create a list Custom Setting that would reference the text to the Field Set. So instead of looping a list of strings, I loop through a list of Custom Settings that contain a reference to the Field Sets.
I don't get an error in the code, but I get one on the page. Can something like this be done?
So I've kind of gotten this to work.
I found I can call the Field set on the visualforce page and put the FieldsetName variable within []
so it looks like Value="{!$ObjectType.Case.FieldSets[FieldSetNameVariable]}"
That will grab the fields and put them on the page. however if it's within the repeat and you try outputfield value="{!Case[f]}" It will return an unspecified error for the page.
Ideas?
and the page would be like this:
Hello,
Did you get any solution for this requirement! I need to implement similar kind of requirement, Can you please share details if you got the solution.
Thanks,
Krishna