• ASHISH VARMA
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
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, and a SELECT query is generated.
I have fetched all deatil records of those fields 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.


Visualforce Code:


<apex:page controller="CustomWorkbench">
  <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>

Apex Code:

public with sharing class CustomWorkbench {

    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 ;
    }*/
}
I have developed a Visualforce page which contains two dropdowns
  1. Will show all Objects in my organisation.
  2. ​Will show all fields based on selection of objects.
​I can multiselect fields from second dropdown, and a SELECT query is generated.
I have fetched all deatil records of those fields 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.


Visualforce Code:


<apex:page controller="CustomWorkbench">
  <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>

Apex Code:

public with sharing class CustomWorkbench {

    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 got following error on step 3.

Challenge Not yet complete... here's what's wrong: 
Couldn’t find Agency records from the Account object.

Can anyone pass this step?
Thanks in advance.

Regards,
LinThaw
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, and a SELECT query is generated.
I have fetched all deatil records of those fields 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.


Visualforce Code:


<apex:page controller="CustomWorkbench">
  <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>

Apex Code:

public with sharing class CustomWorkbench {

    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 everyone.

 

Has anyone attempted to display a dashboard as part of a visualforce page? I have been browsing around and haven't found anything. The reason I ask is that I want to show one of our dashboards on our company's intranet websites, and figured the easiest way to do it would be to display it in visualforce and publish it as a Site that the intranet web could then incorporate into it's layout.

 

If anyone has any hints or tips I'm all ears :)

 

Regards,

Ivar