• Varalaxmi Jangay 6
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
Hi,
I have developed a Visualforce page which contains two dropdownsWill show all Objects in my organisation.
​Will show all fields based on selection of objects.​I can multiselect fields from second dropdown.But I am not able to display those records on Visualforce Page as the data is Dynamic, every time you choose different object their corresponding fileds I need to display different columns,thier records. 
Please help me to sort this problem.

<apex:page controller="DilliScnario2"  >
     <apex:form >
     <apex:pageBlock >
         <apex:outputLabel value="Choose Object : "></apex:outputLabel>
                  <apex:selectList value="{!AllObjectsList}" size="1" onchange="change()">
                      <apex:selectOptions value="{!AllObjects}">
                      </apex:selectOptions>
                  </apex:selectList>
              
                  <apex:actionFunction name="change"  action="{!getAllFields}" reRender="fields1" status="Loading"/><br/>
                  <apex:actionStatus id="Loading" startText="Loading..."></apex:actionStatus>
    
     </apex:pageBlock>
     <apex:pageBlock id="fields1">
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <b><apex:OutputText value="Select {!AllObjectsList} Fields : "></apex:OutputText></b>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <apex:selectList value="{!CorrespondingFields}"  size="5" multiselect="true"> 
             <apex:selectOptions value="{!fieldNames}" >
             </apex:selectOptions>
         </apex:selectList><br/><br/>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        
        <!-- <apex:commandButton value="Generate Query" action="{!DisplayRecords}" status="Loading" reRender="showrecords,querytextarea"/><br/>
      
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <apex:inputTextarea disabled="true" value="{!query1}" rows="2"  cols="100" id="querytextarea"/>-->
     </apex:pageBlock>
     <apex:pageBlock id="showrecords" rendered="true">
         
       <!--<apex:pageBlockTable value="{!DisplayRecords}" var="fields">
            
             <apex:repeat value="{!fieldNameToString}" var="dynamicfields">
               <apex:column value="{!fields[dynamicfields]}" />
             </apex:repeat>
         </apex:pageBlockTable>-->
     </apex:pageBlock>
  </apex:form>
</apex:page>
============================================
public class DilliScnario2 {
 public List<sObject> recordlist { get; set; }
    public String query1 { get; set; }
    public List<String> fieldNameToString { get; set; }
    public List<SelectOption> fieldNames{get; set;}
    public String CorrespondingFields{ get; set; }
    public String AllObjectsList { get; set; }
    
    public class innerWrapperClass{
        List<String> SelectedFieldsName { get; set; }
    }
       
  /*  public PageReference DisplayRecords() {
        if(CorrespondingFields != null){
            integer length = CorrespondingFields.length();
            CorrespondingFields= CorrespondingFields.substring(1,length-1);
            String[] separate = CorrespondingFields.split(',\\s*');
            query1 = 'Select ' + CorrespondingFields + ' from ' + AllObjectsList;
            try{
                recordlist = Database.query(query1);
            }
            catch(Exception es){
                ApexPages.addMessages(es);
            }
            System.debug('recordlist ' + recordlist );
            System.debug('query1 '+query1 );
        }
        return null;
    }*/
    
    public void getAllFields() {
        System.debug('all AllObjectsList' + AllObjectsList);
        fieldNameToString = new List<String>();
        fieldNames = new List<SelectOption>();
        if(AllObjectsList != null){
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Schema.SObjectType ObjectSchema = schemaMap.get(AllObjectsList);
            Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
            
            for(String fieldName: fieldMap.keySet()) {  
                fieldNames.add(new SelectOption(fieldName,fieldName));
                fieldNameToString.add(fieldName);
                //fieldNameToString = (List<String>)fieldNames;
            }
        }
        System.debug('all fields' + fieldNames);
        System.debug('fieldNameToString' + fieldNameToString);
    }

    public List<SelectOption> getAllObjects() {
        List<Schema.sObjectType> gd = Schema.getGlobalDescribe().Values();
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--------Select--------'));
        for(Schema.sObjectType gd1 : gd){
            options.add(new SelectOption(gd1.getDescribe().getName(),gd1.getDescribe().getName()));
        }
        options.sort();
        return options;
    }

 /*  public List<sObject> getDisplayRecords() {
        if(CorrespondingFields != null){
            integer length = CorrespondingFields.length();
            CorrespondingFields= CorrespondingFields.substring(1,length-1);
            String[] separate = CorrespondingFields.split(',\\s*');
            System.debug('separate :' + separate[0] );
            query1 = 'Select ' + CorrespondingFields + ' from ' + AllObjectsList;
            recordlist = Database.query(query1);
            System.debug('recordlist ' + recordlist );
            System.debug('query1 '+query1 );
        }
        return recordlist ;
    }  */
    

}
Hi,
I have a requirement,
While changing the owner of the record, only the user in the below hierarchy must be visible in the lookup dialod box, as shown in the figureUser-added image
Hi,
i am getting the below error while solving the trailhead badges. Can anyone help me plz.User-added image