0

I want my visualforce page to show each of my fieldSets in a pageTable, and the columns of the tables to be the fields present in their fieldSet. I want to be able to do that because I dont want to copy paste all the same code for each of the fieldSet that i have.

for now, my VF page looks like that

<apex:repeat value = "{!$ObjectType.ProductRequest.FieldSets}" var = "fieldSet">
            <apex:variable var="name" value="{**!fieldSet.label.split('_')[0]**}"/>
            <apex:pageBlockSection title="{!name}" columns="1">
                <apex:pageBlockTable value="{!wrappers[name]}" var="wrapper"  id="Table">
                    
                    <apex:column headerValue="#">   <apex:outputText value="{!wrapper.ident}"/> </apex:column>
                    
                    <apex:repeat value="{**!$ObjectType.ProductRequest.FieldSets[fieldSet]**}" var="field">
                        <apex:column headerValue="{**!field.label**}">
                            <apex:inputField value="{**!wrapper.product[field]**}" />
                        </apex:column>
                    </apex:repeat>
                    
            </apex:pageBlockSection>
        </apex:repeat>

I put all the code that I suspect that won't work in bold (in **). Can somebody tell me why referencing a method of a class in VF don't work? same thig for accessing an element of a List with [].

these are my kinds of problems.

thanks.

3
  • What are you trying to accomplish with this, what is your high-level goal? This FieldSet-based implementation is unusual.
    – identigral
    Jun 14 at 17:14
  • I am trying to create a VF page that the users can use for creating quickly a lot of productRequests. But since I have many records types and each of them require diferents fields to create a record, I am trying to automate the use of a record type by attribuating each record type a fieldSet so the non-programers at my my org can easily mange the fields and their order in the fieldSet section
    – Alexis
    Jun 14 at 18:07
  • This sounds like a job for a Screen Flow. Take a look at Building Forms decision guide for more info.
    – identigral
    Jun 14 at 18:27

1 Answer 1

0

You're trying to use Apex, but merge fields only support a subset of the Formula syntax.

<apex:variable var="name" value="{!fieldSet.label.split('_')[0]}"/>

Could be:

<apex:variable var="name" value="{!LEFT(fieldSet.label,FIND('_',fieldset.label))}"/>

However, be advised that apex:variable states:

Note: <apex:variable> does not support reassignment inside of an iteration component, such as <apex:dataTable> or <apex:repeat>. The result of doing so, e.g., incrementing the <apex:variable> as a counter, is unsupported and undefined.

It would be recommended that you write Apex to render the appropriate list of fields from the FieldSet, then use <apex:repeat> / <apex:pageBlockTable> / <apex:panelGrid>, etc to render the form.

1
  • you were right, I used my apex controller to make a Map<String, List<String>> and a Set of String, with the keys of the map and the Set values to be the same. So my first repeat is on the Set, and my second one is on the Lists of my Map accessible with the variable of the first repeat, like <apex:repeat value="{!fieldSetsKeys}" var="fieldSetKey"> <apex:repeat value="{!fieldSets[fieldSetKey]}" var="field">. the values in the Lists are the API names of the fields useb by each fieldSet
    – Alexis
    Jun 15 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.