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
ArchanaRArchanaR 

render button next to a field set (conditionally) based on field set value

 

I want to render a button next to a field set conditionally based on field set value. How can I achieve that. For eg. in the code below, I want to render the button only if the column is "Bill To"

 

 

<apex:pageBlock id="systemDetails" title="System Details" >
                    <apex:pageBlockSection id="PBS" columns="2">
                         <apex:repeat value="{!$ObjectType.Opportunity.FieldSets.System_Information}" var="f">  
                             <apex:outputField value="{!Opportunity[f]}"/>
                             <apex:commandButton value="Copy Bill To" rendered="{!Opportunity[f]='Bill To'}" action="{!copyBillTo}"/>
                         </apex:repeat>
                    </apex:pageBlockSection>
       </apex:pageBlock>      
 
"Bill To" is a field in the fieldset. This is not working. Any idea what could be the issue here.              

 

forecast_is_cloudyforecast_is_cloudy

You can reference the API name (or label and other attributes for that matter) for a field inside a Field Set as such: 

 

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

               {!$ObjectType.Opportunity.Fields[f].name

</apex:repeat>

 

I tried to use that in a render condition though (i.e.  rendered=" {!$ObjectType.Opportunity.Fields[f].name == 'My_Field__c'")  and it didn't seem to work. Not sure why, but perhaps you can try some different combinations of that?

Bhawani SharmaBhawani Sharma

Use this , It works:

 

<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock >
            <apex:repeat value="{!Account.contacts}" var="Conatcts">
                <apex:repeat value="{!$ObjectType.Contact.FieldSets.Contact_Fields}" var="f">
                    <Br/><apex:outputlabel value="{!contains(lower($ObjectType.Contact.Fields[f].label),'bill to')}"/>
                </apex:repeat>
            </apex:repeat>
        </apex:pageBlock>
    </apex:form>
</apex:page>