I have a custom metadata type with the following fields:

  1. Fieldsets referred
  2. Object Name

I have a requirement in which I need to show these multiple fieldsets on a vf page for that particular object. I thought of using nested apex:repeat tags but am not able to get around the solution. My apex and visualforce code is as follows:

Apex Class:

public class FieldSetUIGenerator {
    public List<Credit_Webform__mdt> webformFields { get; set; }
    Public SObject webformObject {get;set;}
    public String objName {get;set;}
    public Map<String,String> fieldsetNames {get;set;}
    public Boolean isSuccess { get; set; }
    public String message { get; set; }
    public Boolean isCompleted { get; set; }
    public String fieldSetName { get; set; }
    public Boolean isFieldSetValid { get; set; }
    public List<String> fieldSetArr {get;set;}
    public Map<String, List<Schema.FieldSetMember>> fieldsetMap{get;set;}
    public List<List<Schema.FieldSetMember>> fieldsList {get; set;}
    public FieldSetUIGenerator() {
        fieldSetName = '';
        fieldsetMap = new Map<String, List<Schema.FieldSetMember>>();
        fieldsList = new List<List<Schema.FieldSetMember>>();
        fieldsetNames = new Map<String,String>();
        webformFields = [SELECT DeveloperName,Fieldsets_Referred__c,Id,Label,Object_Name__c,Page_Referred__c,Process_Name__c,Process_Order__c FROM Credit_Webform__mdt order by Process_Order__c asc];

        isCompleted     = FALSE;

        for(Credit_Webform__mdt str : webformFields){
            fieldSetName +=  str.Fieldsets_Referred__c; 
            objName = str.Object_Name__c;

        webformObject = getNewSobject(objName);
        fieldSetArr = fieldSetName.split(',');

        for(String fsm : fieldSetArr){
          fieldsetMap.put(fsm, readFieldSet(fsm,objName));
            fieldsetNames.put(fsm,fsm.replace('_', ' '));

    public SObject getNewSobject(String objectName){
        Map<String, Schema.SObjectType> globalDescribe = Schema.getGlobalDescribe();
        Schema.SObjectType objectType = globalDescribe.get(objectName);
        Sobject newObject = objectType.newSobject();
        return newObject;

    public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName){
        Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); 
        Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName);
        Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
        Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName);
        return fieldSetObj.getFields(); 


        <div class="slds">
            <apex:form id="frmCandEdit">
                <div class="slds-grid slds-wrap">
                    <div class="slds-col slds-medium-size--4-of-12 slds-p-around--medium">
                        <h3 style="color:black !important" class="slds-text-heading--small slds-m-bottom--large slds-section__title">Basic Information</h3>
                <div class="slds-grid slds-wrap">
                    <apex:repeat value="{!fieldSetArr}" var="fieldset">
                        <div class="slds-col slds-medium-size--12-of-12 slds-p-around--medium">
                            <h3 class="slds-text-heading--small slds-m-bottom--large slds-section__title">{!fieldsetNames[fieldset]}</h3>
                        <apex:repeat value="{!fieldsetMap[fieldset]}" var="field">
                            <div class="slds-col slds-size--1-of-1 slds-medium-size--4-of-12">
                                <div class="slds-form-element slds-p-around--medium">
                                    <div class="slds-form-element__control input-field col s4 filled-in">
                                        <label for="{!field.label}">{!field.label}</label>
                                        <apex:inputField styleClass="validate" html-data-id="{!field.label}" value="{!webformObject[field.fieldPath]}" required="{!OR(field.required, field.dbrequired)}"></apex:inputField>

I need to get the object name and field sets dynamically through a query and use them to create inputfields on the vf page.

  • 2
    you'll get more help if you edit the question and remove all the debug statements and the parts of the VF page that are irrelevant to this question - just focus on the apex:repeat. See How to Ask – cropredy Aug 23 at 0:46

Your Answer

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

Browse other questions tagged or ask your own question.