You need to sign in to do that
Don't have an account?
munna123
how to get the list of records with selected checkin fields of a selected object
hii all...
actually i created a dropdown list for some objects. when we select an object, its fields will be generated with checkins. but am not able to get the records with checkin fields. i created a "view report"button to get records. but how to get them by clicking the "view report" button
here is my code..
vf page:
<apex:page controller="selectlist">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="select the required objects below" columns="1" collapsible="false">
<apex:pageBlockSectionItem >
<apex:outputlabel value="Object :" />
<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__c" itemLabel="merchandise__c" />
<apex:selectOption itemValue="invoice__c" itemLabel="invoice__c" />
<apex:selectOption itemValue="case" itemLabel="case" />
<apex:selectOption itemValue="solution" itemLabel="solutions" />
<apex:selectOption itemValue="document" itemLabel="document" />
<apex:selectOption itemValue="report" itemLabel="report" />
<apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
</apex:selectList>
<apex:actionSupport event="onchange" rerender="Fieldnames"/>
<apex:commandbutton value="add"/>
</apex:actionRegion>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection title="these are the fields of selected sobject....">
<apex:pageBlockSectionItem >
<apex:outputlabel value="Field Names :"/>
<apex:outputPanel id="Fieldnames">
<apex:actionRegion >
<fieldset>
<apex:panelGrid columns="1" >
<apex:selectCheckboxes value="{!selectedField}" layout="linedrection-vertical">
<apex:selectOptions value="{!ObjectFields}" />
</apex:selectCheckboxes>
<apex:commandbutton value="view report" />
</apex:panelGrid>
</fieldset>
</apex:actionRegion>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
global with sharing class selectlist
{
public Map <String, Schema.sObjectType> schemaMap = Schema.getGlobalDescribe();
public String selectedObject {get; set;}
public String selectedField {get; set;}
public account sel{set;get;}
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 = new Map<String, Schema.sObjectField>();
if(ObjectSchema!=null){
fieldMap = ObjectSchema.getDescribe().fields.getMap();
}
List<SelectOption> fieldNames = new List<SelectOption>();
for (String fieldName: fieldMap.keySet())
{
fieldNames.add(new SelectOption(fieldName,fieldName));
}
return fieldNames;
}
}
actually i created a dropdown list for some objects. when we select an object, its fields will be generated with checkins. but am not able to get the records with checkin fields. i created a "view report"button to get records. but how to get them by clicking the "view report" button
here is my code..
vf page:
<apex:page controller="selectlist">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="select the required objects below" columns="1" collapsible="false">
<apex:pageBlockSectionItem >
<apex:outputlabel value="Object :" />
<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__c" itemLabel="merchandise__c" />
<apex:selectOption itemValue="invoice__c" itemLabel="invoice__c" />
<apex:selectOption itemValue="case" itemLabel="case" />
<apex:selectOption itemValue="solution" itemLabel="solutions" />
<apex:selectOption itemValue="document" itemLabel="document" />
<apex:selectOption itemValue="report" itemLabel="report" />
<apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
</apex:selectList>
<apex:actionSupport event="onchange" rerender="Fieldnames"/>
<apex:commandbutton value="add"/>
</apex:actionRegion>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection title="these are the fields of selected sobject....">
<apex:pageBlockSectionItem >
<apex:outputlabel value="Field Names :"/>
<apex:outputPanel id="Fieldnames">
<apex:actionRegion >
<fieldset>
<apex:panelGrid columns="1" >
<apex:selectCheckboxes value="{!selectedField}" layout="linedrection-vertical">
<apex:selectOptions value="{!ObjectFields}" />
</apex:selectCheckboxes>
<apex:commandbutton value="view report" />
</apex:panelGrid>
</fieldset>
</apex:actionRegion>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
global with sharing class selectlist
{
public Map <String, Schema.sObjectType> schemaMap = Schema.getGlobalDescribe();
public String selectedObject {get; set;}
public String selectedField {get; set;}
public account sel{set;get;}
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 = new Map<String, Schema.sObjectField>();
if(ObjectSchema!=null){
fieldMap = ObjectSchema.getDescribe().fields.getMap();
}
List<SelectOption> fieldNames = new List<SelectOption>();
for (String fieldName: fieldMap.keySet())
{
fieldNames.add(new SelectOption(fieldName,fieldName));
}
return fieldNames;
}
}
Please mark this as Best Answer if it really help you.
Thanks
Sandeep Singhal
http://www.codespokes.com/
Selected field names are displayed on the Apex Message section.
<apex:page controller="SelectList">
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page
<!-- End Default Content REMOVE THIS -->
<apex:pageMessages id="mymsg" />
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Select Object">
<apex:actionregion >
<apex:selectlist value="{!selectedObject}" size="1" id="idObjectList">
<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__c" itemLabel="merchandise__c" />
<apex:selectOption itemValue="invoice__c" itemLabel="invoice__c" />
<apex:selectOption itemValue="case" itemLabel="case" />
<apex:selectOption itemValue="solution" itemLabel="solutions" />
<apex:selectOption itemValue="document" itemLabel="document" />
<apex:selectOption itemValue="report" itemLabel="report" />
<apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
<apex:actionsupport event="onchange" action="{!RetrieveObjectFields}" rerender="idFieldList"/>
</apex:selectlist>
</apex:actionregion>
</apex:pageBlockSection>
<apex:pageblocksection id="idFieldList" title="Fields of Selected Object" columns="1">
<apex:actionRegion >
<apex:pageblockTable value="{!ObjectFields}" var="item">
<apex:column >
<apex:inputCheckbox value="{!item.selected}"/>
</apex:column>
<apex:column value="{!item.fieldName}"/>
</apex:pageblockTable>
</apex:actionRegion>
<apex:commandbutton value="view report" action="{!ViewSelectedField}"/>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
public class SelectList
{
public string selectedObject{get;set;}
public string selectedField{get;set;}
/* public List<SelectOption> getObjectFields()
{
Map<String, Schema.sObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
Map<String, Schema.sObjectField> fieldMap = new Map<String, Schema.sObjectField>();
if(ObjectSchema!=null){
fieldMap = ObjectSchema.getDescribe().fields.getMap();
}
List<SelectOption> fieldNames = new List<SelectOption>();
for (String fieldName: fieldMap.keySet())
{
fieldNames.add(new SelectOption(fieldName,fieldName));
}
return fieldNames;
}
*/
public List<WrappedObjectField> ObjectFields{get;set;}
public void RetrieveObjectFields()
{
Map<String, Schema.sObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
Map<String, Schema.sObjectField> fieldMap = new Map<String, Schema.sObjectField>();
if(ObjectSchema!=null){
fieldMap = ObjectSchema.getDescribe().fields.getMap();
}
this.ObjectFields = new List<WrappedObjectField>();
for (String fieldName: fieldMap.keySet())
{
ObjectFields.add(new WrappedObjectField(false,fieldName));
}
}
public void ViewSelectedField()
{
string selectedFieldNames ='';
for (WrappedObjectField wf : ObjectFields)
{
if (wf.selected == true)
{
selectedfieldNames += wf.fieldName + ';';
}
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Selected Field(s): ' + selectedfieldNames);
ApexPages.addMessage(myMsg);
}
public class WrappedObjectField
{
public boolean selected {get;set;}
public string fieldName {get;set;}
WrappedObjectField(boolean b,string s)
{
selected = b;
fieldName = s;
}
}
}