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
Eric.HeEric.He 

How to set the mandatory of the fields in the field sets

Hi All,

 

Is there anybody know how to set the mandatory of the fields in the field sets.  After Summer 11', salesforce has added more properties for field sets, like DBRequired, Required. Origianlly, we had the problem to set some of the fields required in the field sets, after the delivery of Summer 11',  i thought this problem could be resolved by the new property. Below is one of my codes:

 

 

<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:repeat value="{!$ObjectType.Account.FieldSets.Billing_Address}" var="i">                   
                    <apex:inputField value="{!Account[i]}" required="{!$ObjectType.Account.Fields[i].Required}" />
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:pageBlock>        
    </apex:form>
</apex:page>

But after doing this, i always got the error message: Unknown property 'Field.Required'

Error is in expression '{!$ObjectType.Account.Fields[i].Required}' in component <apex:inputField> in page accountbillingaddress
Is there anybody can help me with this problem? Thanks in advance!

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

I think you want the DB required flag, which specifies that the value is required (the required flag means the field cannot be removed from the fieldset on an installed fieldset).

 

Since this is a property of the fieldset element, you access it via the fieldset element, not the field.

 

In your case, the repeat iterates over the fieldset, setting var i to sucessive entries. So the syntax would be

 

 <apex:inputField value="{!Account[i]}" required="{!i.DBRequired}" />

All Answers

dipudipu

In this case the required property indicates that this field cannot be removed by the administrator from the field set.

aballardaballard

I think you want the DB required flag, which specifies that the value is required (the required flag means the field cannot be removed from the fieldset on an installed fieldset).

 

Since this is a property of the fieldset element, you access it via the fieldset element, not the field.

 

In your case, the repeat iterates over the fieldset, setting var i to sucessive entries. So the syntax would be

 

 <apex:inputField value="{!Account[i]}" required="{!i.DBRequired}" />
This was selected as the best answer
Eric.HeEric.He

Thank you very much, this is really helpful!

 

But I don't think the required property means the field cannot be removed from the fieldset on an installed fieldset. According the salesforce's documentation, the DBRequired indicates whether the field is required for the object, and Required indicates whether the field is required in the field set. The DBRequired is defined on the field itself, but the Required is defined on the field set level. It's pretty much like the page layout, where we can also specify the mandatory for some fields, even if those fields are not defined as required during the field definition. What do you think?

 

Anyway, my problem is solved after I change the code to:

 

 

<apex:inputField value="{!Account[i]}" required="{!i.Required}" />

 Thanks again!

 

 

mmrrrmmrrr

My code is given below, but the fields are not showing mandatory - I am confusing, can you please help me?

 

<apex:page standardcontroller="Opportunity">

    <apex:form > <br/> <center> <apex:commandButton value="Save" action="{!Save}"/> &nbsp;&nbsp;

         <!-- <apex:commandButton value="Save & new" action="{!Save & new}"/> --->

         <apex:commandButton value="Cancel" action="{!Cancel}"/> </center> <br/>

               <apex:pageBlock title="Opportunity Information">

                       <apex:pageBlockSection columns="4">

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

                                            <apex:inputField value="{!Opportunity[f]}" required="{!f.Required}" /> <br/>

                                   </apex:repeat>

                       </apex:pageBlockSection>

             </apex:pageBlock>

    </apex:form>

</apex:page>