Working with Field Sets
You can use dynamic bindings to display field sets on your Visualforce pages. A field set is a grouping of fields. For example, you could have a field set that contains fields describing a user's first name, middle name, last name, and business title. If the page is added to a managed package, administrators can add, remove, or reorder fields in a field set to modify the fields presented on the Visualforce page without modifying any code. Field sets are available for Visualforce pages on APIversion 21.0 or above. You can have up to 50 field sets referenced on a single page.
Working with Field Sets Using Visualforce
<apex:page standardController="Contact"> <apex:repeat value="{!$ObjectType.Contact.FieldSets.properNames}" var="f"> <apex:outputText value="{!Contact[f]}" /><br/> </apex:repeat> </apex:page>
Property Name | Description |
---|---|
DBRequired | Indicates whether the field is required for the object |
FieldPath | Lists the field’s spanning info |
Label | The UI label for the field |
Required | Indicates whether the field is required in the field set |
Type | The data type for the field |
<apex:page standardController="Contact"> <apex:pageBlock title="Fields in Proper Names"> <apex:pageBlockTable value="{!$ObjectType.Contact.FieldSets.properNames}" var="f"> <apex:column value="{!f}"> <apex:facet name="header">Name</apex:facet> </apex:column> <apex:column value="{!f.Label}"> <apex:facet name="header">Label</apex:facet> </apex:column> <apex:column value="{!f.Type}" > <apex:facet name="header">Data Type</apex:facet> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
{!$ObjectType.Contact.FieldSets.Spectre__properNames}
Working with Field Sets Using Apex
Fields in a field set are automatically loaded when your Visualforce page uses a standard controller. When using a custom controller, you need to add the required fields to the SOQL query for the page. Apex provides two Schema objects that allow you to discover field sets and the fields they contain, Schema.FieldSet and Schema.FieldSetMember. For information about these two system classes, see “FieldSet Class” in the Force.com Apex Code Developer's Guide.
Sample: Displaying a Field Set on a Visualforce Page
public class MerchandiseDetails { public Merchandise__c merch { get; set; } public MerchandiseDetails() { this.merch = getMerchandise(); } public List<Schema.FieldSetMember> getFields() { return SObjectType.Merchandise__c.FieldSets.Dimensions.getFields(); } private Merchandise__c getMerchandise() { String query = 'SELECT '; for(Schema.FieldSetMember f : this.getFields()) { query += f.getFieldPath() + ', '; } query += 'Id, Name FROM Merchandise__c LIMIT 1'; return Database.query(query); } }
<apex:page controller="MerchandiseDetails"> <apex:form > <apex:pageBlock title="Product Details"> <apex:pageBlockSection title="Product"> <apex:inputField value="{!merch.Name}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Dimensions"> <apex:repeat value="{!fields}" var="f"> <apex:inputField value="{!merch[f.fieldPath]}"
required="{!OR(f.required, f.dbrequired)}"/> </apex:repeat> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Field Set Considerations
- If a field is marked as Available for the Field Set, it exists in the field set, but the developer hasn’t presented it on the packaged Visualforce page. Administrators can display the field after the field set is deployed by moving it from the Available column to the In the Field Set column.
- If a field is marked as In the Field Set, the developer has rendered the field on the packaged Visualforce page by default. Administrators can remove the field from the page after the field set is deployed by removing it from the In the Field Set column.
The order in which a developer lists displayed fields determines their order of appearance on a Visualforce page.
- Subscribers with installed field sets can add fields that your page didn’t account for. There is no way to conditionally omit some fields from a field set iteration, so make sure that any field rendered through your field set works for all field types.
- We recommend that you add only non-essential fields to your field set. This ensures that even if a subscriber removes all fields in the field set, Visualforce pages that use that field set still function.
Various trademarks held by their respective owners.
Harrah's Resort Atlantic City - Mapyro
ReplyDeleteInformation, maps, and reviews for 논산 출장마사지 Harrah's Resort Atlantic City - MGM Grand Hotel in Atlantic City - 청주 출장샵 view the 청주 출장샵 map Harrah's 나주 출장샵 Resort Atlantic City 김제 출장샵 - Mapyro.