You need to sign in to do that
Don't have an account?
munna123
how to create checkboxes for field types to get selected field values
hiii,
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;
}
}
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;
}
}
Your code seems OK. What error are you getting? When it happens?
Regards.
Which object are you getting this error? Be sure that when you populates your picklist you're appending the suffix notation __c to your custom objects in the picklist's itemValue attribute. Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Have you solved your problem?
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.