You need to sign in to do that
Don't have an account?
Dynamic Records and columns for Dynamic objects in VISUAL FORCE PAGE
Hi,
I WANT DISPLAY THE DYNAMIC RECORDS AND COLUMNS FOR DYNAMIC OBJECTS BUT I GOT THE DYNAMIC COLUMNS BUT THE RECORDS ARE NOT PRESENT IN THE TABLE. PLEASE HELP ME
DYNAMICRECORDS CLASS
========================
public with sharing class DynamicRecords {
public List<selectoption> allobjects{ get; set; }
list<String> lstfield=new list<String>();
public String selectedobject { get; set; }
public map<String , String> mapFieldToShow{get;set;}
public DynamicRecords()
{ allobjects= new List<selectoption>();
allobjects.add(new selectoption('','---Select Object---'));
allobjects.add(new selectoption('Account','Accounts'));
allobjects.add(new selectoption('Contact','Contacts'));
allobjects.add(new selectoption('Opportunity','Opportunities'));
allobjects.add(new selectoption('Lead','Leads'));
allobjects.add(new selectoption('Case','Cases'));
}
public List<String> strFields { get; set; }
public String Str {get;set;}
public List<Sobject> Records { get; set; }
public PageReference RecordsAll() {
Str='';
map<String , String> mapFieldToShow=new map<String , String>();
System.debug('========================'+selectedobject );
strFields = new List<String>();
Map<String, Schema.sobjectfield> AllFields = Schema.getGlobalDescribe().get(selectedobject).getDescribe().fields.getMap();
// system.debug('============================='+AllFields.keyset() );
SObjectType objToken = Schema.getGlobalDescribe().get(selectedobject );
DescribeSObjectResult objDef = objToken.getDescribe();
Map<String, SObjectField> fieldmap = objDef.fields.getMap();
for(Schema.sobjectField obj: AllFields.values())
lstfield.add(String.valueOf(obj));
for(Schema.sobjectField F: AllFields.values())
{
SObjectField fieldToken = F;
DescribeFieldResult selectedField = fieldToken.getDescribe();
// lstflabel.add(selectedfield.getLabel());
mapFieldToShow.put(selectedField.getLabel() ,selectedField.getLocalName());
// system.debug('============================='+mapFieldToShow.keyset());
strFields .add(String.valueOf(F));
if(Str=='')
Str=String.valueOf(F);
else
Str= Str+','+String.valueOf(F);
}
//system.debug('===========Fields=================='+strFields );
//system.debug('===========Fields==List================'+lstfield);
system.debug('============================='+Str );
String Squery='select '+Str+' from '+selectedobject ;
system.debug('=================squery======================'+Squery);
Records = new List<Sobject>();
//if(selectedobject == 'Account')
Records =database.query(Squery);
// for(Sobject c: Records)
// system.debug('=================squery======================'+c);
return null;
}
}
-------------------
DYNAMIC PAGE
==================
<apex:page controller="DynamicRecords">
<apex:form >
<!-- <apex:actionfunction name="pass" action="" rerender="out"/>-->
<apex:selectList size="1" value="{!selectedobject}" >
<apex:selectoptions value="{!allobjects}" ></apex:selectoptions>
<apex:commandButton value="Go" action="{!RecordsAll}"/>
</apex:selectList>
<apex:pageBlock id="out">
<apex:pageblocktable columns="{!strFields.size}" value="{!Records }" var="R" >
<apex:repeat value="{!strFields }" var="F" >
<apex:column width="50px" style="font-size:15; font-color:" headerValue="{!F}" value="{!R[mapFieldToShow[F]]}" >
</apex:column>
</apex:repeat>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
What is the value of squery variable that you are getting in debug. Can you paste that here.
Also you are not using the rerender. You need to say rerender the pageblock. Else it will not refresh.