You need to sign in to do that
Don't have an account?
Rahul Gupta 166
Issue to make dynamic table header on basis of picklist
Hi, i have a two picklist value one has a list of object and other is a list of the fields related to object pick list(more than one field can be selected)
If a object is selected and related field are selected it should create a table with records for a particular object.
This is now working for one field in the Particular object.
when I select the multiple fields for an object it shows error
Exception: Invalid field name for SObject Account
Below is vf page for same :
Please help me to create a table with more than one field with record
Thanks in Advance
Rahul
If a object is selected and related field are selected it should create a table with records for a particular object.
This is now working for one field in the Particular object.
when I select the multiple fields for an object it shows error
Exception: Invalid field name for SObject Account
Below is vf page for same :
<apex:page controller="objectController1" showHeader="false" sidebar="false" > <head> <apex:stylesheet value="{!URLFOR($Resource.LIGHTNING_RESOURCE_NAME, 'assets/styles/salesforce-lightning-design-system-vf.css')}" /> </head> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputlabel value="Object Names :"/> <apex:actionRegion > <apex:selectList value="{!selectedObject}" size="1"> <apex:selectOptions value="{!ObjectNames}"/> <apex:actionSupport event="onchange" rerender="myFields"/> </apex:selectList> </apex:actionRegion> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputlabel value="Field Names :"/> <apex:outputPanel id="myFields"> <apex:actionRegion > <apex:selectList value="{!selectedField}" size="10" multiselect="true"> <apex:selectOptions value="{!ObjectFields}"/> </apex:selectList> </apex:actionRegion> </apex:outputPanel> </apex:pageBlockSectionItem> <Center> <apex:commandButton value="Fetch Fields" action="{!Fetch}"/> </Center> </apex:pageBlockSection> </apex:pageBlock> <apex:outputPanel layout="block"> <apex:pageBlock > <apex:pageBlockSection > <apex:pageblockTable value="{!lstobj}" var="querydata"> <apex:repeat value="{!fnlFields}" var="coldata"> <apex:column value="{!querydata[coldata]}"> </apex:column> </apex:repeat> </apex:pageblockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>Below is Controller for the Same :
public class objectController1{ public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); public String selectedObject {get; set;} public String selectedField {get; set;} public String picklistValue {get; set;} public List<sObject> lstobj {get; set;} public List<String> lstfields {get; set;} public List<String> fnlFields {get;set;} public List<SelectOption> fieldNames {get; set;} public List<wrapData> bindData {get;set;} Public objectController1(){ selectedObject ='account'; //system.debug('HI This is fields'+selectedField ); } 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(); fieldNames = new List<SelectOption>(); for (String fieldName: fieldMap.keySet()){ fieldNames.add(new SelectOption(fieldName,fieldName)); //fieldMap.get(fieldName).getDescribe().getLabel();//It provides to get the object fields label. } System.debug('fieldNames-----'+fieldNames); return fieldNames; } public PageReference Fetch(){ lstobj = new List<sObject>(); lstfields= new List<String>(); bindData = new List<wrapData>(); fnlFields = new List<String>(); //System.debug('Select'+selectedField +'From'+selectedObject); String s1= selectedField.removeStart('['); String s2= s1.removeEnd(']'); String Query='Select '+s2+' From '+selectedObject; lstobj= Database.query(Query); System.debug('List '+lstobj); lstfields = s2.split(','); //System.debug('List of fields '+lstfields); for(String s : lstfields){ fnlFields.add(s); } System.debug(fnlFields); //bindData.add(new wrapData(selectedField,lstobj)); return null; } }
Please help me to create a table with more than one field with record
Thanks in Advance
Rahul
Could you post the source for the class wrapData ?
Regards
I am not using Wrap data any more in the class.
... a simple trim and life goes on but you will have other problems with the addresses.
Some fields will have to be excluded or modified.
"Unsupported type common.api.soap.wsdl.Address encountered."
Best regards
Alain
You can try this code, it will work for you..
The visualforce page is here:
Mark it best answer if it is working fine. Have a great day!!
Thanks & Regards
Mohit Sharma (1028)
Great work but it is still not stable (more complete code step by step at least).
- 35: <apex:pageBlock
- Error; unexpected token: 'From' Error is in expression '{!Fetch}' in component <apex:commandButton> in page objectcontroller1: Class.objectController1.Fetch: line 69, column 1 if you change the page size and click on "Fetch" again.
- and stiil Unsupported type common.api.soap.wsdl.Address encountered. if you want all the fields of Account for my developer org.
The idea of Rahul Gupta is excellent and your improvement is great but it is quite difficult to have a stable result.reR> (a typo when you have done your copy/paste) but it lacks perhaps some lines of your code.Regards
Alain