You need to sign in to do that
Don't have an account?
AYUSH JAIN 29
Error: not found ListRec in VFPage pageBlockTable
<apex:page controller="dynamicObjectRecord_cntlr" >
<apex:form >
<apex:pageBlock title="Dynamic Object and it's Records">
<apex:pageBlockSection title="SeleObject Information">
<apex:inputText label="Object Name:" value="{!sobj}"/>
<apex:commandButton value="Search" action="{!search}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Records of {!sobj}">
<apex:pageBlockTable value="{!listRec}" var="a">
<apex:column headerValue="ID" value="{!a.id}"/>
<apex:column headerValue="Name" value="{!a.name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------
public class dynamicObjectRecord_cntlr {
Public sobject obj {get;set;}
public String sobj { get; set; }
public Map<string,Schema.sobjectType> mobj;
public Set<String> s_allObj;
public List<String> l_allObj;
public List<sObject> listRec {get;set;}
public Boolean Opresent;
public dynamicObjectRecord_cntlr ()
{ obj = null;
sobj= null;
mobj = new Map<String,Schema.sobjectType>();
s_allObj = new Set<String>();
l_allObj = new List<String>();
Opresent = false;
listRec = new List<sobject>();
}
public PageReference search() {
mobj= Schema.getGlobalDescribe();
s_allobj = mobj.keySet();
l_allObj.addAll(s_allobj);
System.debug('Selected value is --'+sobj);
for(String s:l_allObj)
{
if(s==sobj){
Opresent=true;
break;
}
}
if(Opresent==true)
{
String query = 'SELECT id,Name from '+sobj +' LIMIT 50';
System.debug('Query written is '+query);
ListRec = Database.query(query);
System.debug('List of Rec'+ListRec);
}
return null;
}
}
<apex:form >
<apex:pageBlock title="Dynamic Object and it's Records">
<apex:pageBlockSection title="SeleObject Information">
<apex:inputText label="Object Name:" value="{!sobj}"/>
<apex:commandButton value="Search" action="{!search}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Records of {!sobj}">
<apex:pageBlockTable value="{!listRec}" var="a">
<apex:column headerValue="ID" value="{!a.id}"/>
<apex:column headerValue="Name" value="{!a.name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------
public class dynamicObjectRecord_cntlr {
Public sobject obj {get;set;}
public String sobj { get; set; }
public Map<string,Schema.sobjectType> mobj;
public Set<String> s_allObj;
public List<String> l_allObj;
public List<sObject> listRec {get;set;}
public Boolean Opresent;
public dynamicObjectRecord_cntlr ()
{ obj = null;
sobj= null;
mobj = new Map<String,Schema.sobjectType>();
s_allObj = new Set<String>();
l_allObj = new List<String>();
Opresent = false;
listRec = new List<sobject>();
}
public PageReference search() {
mobj= Schema.getGlobalDescribe();
s_allobj = mobj.keySet();
l_allObj.addAll(s_allobj);
System.debug('Selected value is --'+sobj);
for(String s:l_allObj)
{
if(s==sobj){
Opresent=true;
break;
}
}
if(Opresent==true)
{
String query = 'SELECT id,Name from '+sobj +' LIMIT 50';
System.debug('Query written is '+query);
ListRec = Database.query(query);
System.debug('List of Rec'+ListRec);
}
return null;
}
}
Please try this: Hope this helps you!
If this helps you, please mark it as solved so that it will be available for others as a proper solution.
Thanks and Regards
at this time sobject's type is map and your key is name.so we are doing this.
please mark above solution as best answer.if your problem solved.
thanks