function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
munna123munna123 

how to retrieve records with selected fields values when checkedin from list of field types with checkboxes


 my requirement is when i select the required object fom dropdown and click "add" button, i have to get the list of fields of that particular object with checkboxes. when i checkin some fields like phone, name and all then i need to get all the records of that object with the selected field values. i have a program regarding this. but the thing is its not working for custom objects. it is giving some error... and i want to improve my program so that if i checkin and click " view report" button, i have to get the records of that particular object with selected fields and the list of notes and attachments (if present) for all records of that selected object...
 
here is my code

vf page:
-----------
<apex:page controller="objectController">
<apex:form > 
      <apex:pageBlock >
          <apex:pageBlockSection title= "select the objects below">
<apex:pageBlockSectionItem >
                  <apex:outputlabel value = "Object Names :" /> 
                      <apex:actionRegion >      
                           <apex:selectList value="{!selectedObject}" size="1">
            <apex:selectOption itemValue="Account" itemLabel="Account" />
            <apex:selectOption itemValue="Contact" itemLabel="Contact"/>
            <apex:selectOption itemValue="Lead" itemLabel="Lead" />
            <apex:selectOption itemValue="report" itemLabel="report" />
            <apex:selectOption itemValue="campaign" itemLabel="campaign" />
            <apex:selectOption itemValue="merchandise" itemLabel="merchandise" />
            <apex:selectOption itemValue="invoice" itemLabel="invoice" />
            <apex:selectOption itemValue="case" itemLabel="case" />
            <apex:selectOption itemValue="solution" itemLabel="solutions" />
            <apex:selectOption itemValue="document" itemLabel="document" />
            <apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
            <apex:actionSupport event="onchange" rerender="myFields"/>
                            </apex:selectList>
                          <apex:commandbutton value="add"/>
                     </apex:actionRegion>                         
              </apex:pageBlockSectionItem>
               </apex:pageBlockSection>
          
<apex:pageBlockSection title ="these are the fields....">
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Field Names :"/>   
                      <apex:outputPanel id="myFields">   
                        <apex:actionRegion >  
                           <apex:selectCheckboxes value="{!selectedField}">
    <apex:selectOptions value="{!ObjectFields}" />
    </apex:selectCheckboxes>
      <apex:commandbutton value="view report"/>     
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
          </apex:pageBlockSection>
             
      </apex:pageBlock>
  </apex:form>
</apex:page>

apex:
------------
public class objectController
{
    public Map <String, Schema.sObjectType> schemaMap = Schema.getGlobalDescribe();
    public String selectedObject {get; set;}
    public String selectedField {get; set;}
    
    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(name,name));
        }
        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(fieldName,fieldName));
             
            }
            return fieldNames;
      }       
}