1

I have developed page to display..object,itsfields,childobjects,relationships and childobjfields

right now i have a problem with to render the child object fields..when we do change in parent objects... it should render by according to respective child object fields.

Class:

public with sharing class ConfigurationController {

    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    public String selectedObject {get; set;}
    public String selectedField {get; set;}
    public String selectedChildobject {get; set;}
    public String selectedchildField {get; set;}
    public String Relationship {get; set;}

    Public ConfigurationController() {
        selectedObject = 'Account';
        selectedChildobject = 'Account';
    }

    public List<SelectOption> getObjectNames() {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for (String name : entities) {
            objNames.add(new SelectOption(schemaMap.get(name).getDescribe().getName() , schemaMap.get(name).getDescribe().getLabel() ));
        }
        return objNames;
    }

    public List<SelectOption> getObjectFields() {
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
        Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
        List<SelectOption> fieldNames = new List<SelectOption>();
        for (String fieldName : fieldMap.keySet()) {
            fieldNames.add(new SelectOption(fieldMap.get(fieldName).getDescribe().getLabel(), fieldMap.get(fieldName).getDescribe().getLabel()));
        }
        return fieldNames;
    }

    public List<SelectOption> getRelatedObjects() {
        map<string, string> relatedObjectsMap = new map<string, string>();
        system.debug('selectedObject :' + selectedObject);
        list<Schema.Childrelationship> relatedObjectsList = Schema.getGlobalDescribe().get(selectedObject).getdescribe().getChildRelationships();
        system.debug('relatedObjectsList :' + relatedObjectsList);
        List<SelectOption> ChildobjNames = new List<SelectOption>();
        for (Schema.Childrelationship  relatedObject : relatedObjectsList) {
            if (relatedObject.getChildSObject().getDescribe().isUpdateable()
                    &&
                    relatedObject.getChildSObject().getDescribe().getKeyPrefix() != null
                    &&
                    !relatedObject.getChildSObject().getDescribe().isCustomSetting()
                    &&
                    relatedObject.getChildSObject().getDescribe().isCreateable()
               )
                ChildobjNames.add(new SelectOption(relatedObject.getChildSObject().getDescribe().getName(), relatedObject.getChildSObject().getDescribe().getLabel()));
            system.debug('ChildobjNames :' + ChildobjNames);
        }
        return ChildobjNames;
    }

    public List<SelectOption> getRelationships() {
        map<string, string> relatedObjectsMap = new map<string, string>();
        system.debug('selectedObject :' + selectedObject );
        list<Schema.Childrelationship> relatedObjectsList = Schema.getGlobalDescribe().get(selectedObject).getdescribe().getChildRelationships();
        system.debug('relatedObjectsList :' + relatedObjectsList);
        List<SelectOption> Relationships = new List<SelectOption>();
        for (Schema.Childrelationship  relatedObject : relatedObjectsList) {
            if (relatedObject.getChildSObject().getDescribe().isUpdateable()
                    &&
                    relatedObject.getChildSObject().getDescribe().getKeyPrefix() != null
                    &&
                    !relatedObject.getChildSObject().getDescribe().isCustomSetting()
                    &&
                    relatedObject.getChildSObject().getDescribe().isCreateable()
               )
                if (relatedObject.getRelationshipName() != null) {
                    Relationships.add(new SelectOption(relatedObject.getRelationshipName(), relatedObject.getRelationshipName()));
                }
            system.debug('Relationships :' + Relationships);
        }
        return Relationships;
    }

    public List<SelectOption> getChildObjectFields() {
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        system.debug('selectedChildobject :' + selectedChildobject);
        Schema.SObjectType ObjectSchema = schemaMap.get(selectedChildobject);
        Map<String, Schema.SObjectField> ChildfieldMap = ObjectSchema.getDescribe().fields.getMap();
        List<SelectOption> ChildfieldNames = new List<SelectOption>();
        for (String ChildfieldName : ChildfieldMap.keySet()) {
            ChildfieldNames.add(new SelectOption(ChildfieldMap.get(ChildfieldName).getDescribe().getLabel(), ChildfieldMap.get(ChildfieldName).getDescribe().getLabel()));
        }
        return ChildfieldNames;
    }
}

Vf page:

<apex:page controller="ConfigurationController" sidebar="false"> 
<apex:form > 
  <apex:pageBlock >
      <apex:pageBlockSection columns="2" title="ParentSection">

          <apex:pageBlockSectionItem >
              <apex:outputlabel value="Object:"/> 
                  <apex:actionRegion >      
                       <apex:selectList value="{!selectedObject}" size="1">
                                <apex:selectOptions value="{!ObjectNames}"/>
                                <apex:actionSupport event="onchange" rerender="myFields,childobj,relationship,childfields1"/>
                       </apex:selectList>
                 </apex:actionRegion>                         
          </apex:pageBlockSectionItem>

          <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Fields:"/>   
                  <apex:outputPanel id="myFields">   
                    <apex:actionRegion >  
                       <apex:selectList value="{!selectedField}" size="1">
                            <apex:selectOptions value="{!ObjectFields}"/>
                        </apex:selectList>
                    </apex:actionRegion>      
                 </apex:outputPanel>
          </apex:pageBlockSectionItem>

      </apex:pageBlockSection>

       <apex:pageBlockSection columns="3" title="ChildSection"> 

          <apex:pageBlockSectionItem >
              <apex:outputlabel value="ChildObjects:"/> 
                  <apex:outputPanel id="childobj">   
                  <apex:actionRegion >      
                       <apex:selectList value="{!selectedChildobject}" size="1">
                                <apex:selectOptions value="{!RelatedObjects}"/>  
                                <apex:actionSupport event="onchange" rerender="childfields"/>
                        </apex:selectList>
                 </apex:actionRegion>
                 </apex:outputPanel>                         
          </apex:pageBlockSectionItem>

          <apex:pageBlockSectionItem >
              <apex:outputlabel value="Relationships:"/> 
                 <apex:outputPanel id="relationship">
                 <apex:actionRegion >      
                       <apex:selectList value="{!Relationship}" size="1">
                                <apex:selectOptions value="{!Relationships}"/>
                        </apex:selectList>
                 </apex:actionRegion>
                 </apex:outputPanel>                          
          </apex:pageBlockSectionItem>

          <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Fields:"/>   
                  <apex:outputPanel id="childfields">    
                    <apex:actionRegion >  
                       <apex:selectList value="{!selectedchildField}" size="1">
                            <apex:selectOptions value="{!ChildObjectFields}"/>
                        </apex:selectList>
                    </apex:actionRegion>      
                  </apex:outputPanel>     
          </apex:pageBlockSectionItem>

      </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:form>

0

The issue is not that it is not re-rendering but actually the way you have written your code, it means it is dependent on the value of

selectedObject

However you are not explicitly updating this when you select a new value in the dropdown for selected object. This happens because you are using the standard setter / getter and have not provided your own implementation. What you need to do is update the setter of

selectedObject

so that it looks something like this

public String selectedObject { get; set { selectedObject = value; selectedChildobject = value; } }

Hope this helps.

| improve this answer | |

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.