You need to sign in to do that
Don't have an account?
Mohammed Ikram 7
I have controller which returns the following
public class MixedObjectVFController {
public static List<List<String>> getObjectList(){
List<List<String>> strList = new List<List<String>>();
List<Account> acc = [select name,phone,AccountNumber from account limit 100];
for(account a : acc){
List<String> tempList = new List<String>();
tempList.add('account');
tempList.add(a.name);
tempList.add(a.phone);
tempList.add(a.AccountNumber );
strList.add(tempList);
}
List<contact> cList = [select name,phone,email from contact limit 100];
for(contact a : cList){
List<String> tempList = new List<String>();
tempList.add('contact');
tempList.add(a.name);
tempList.add(a.phone);
tempList.add(a.email );
strList.add(tempList);
}
return strList;
}
}
public static List<List<String>> getObjectList(){
List<List<String>> strList = new List<List<String>>();
List<Account> acc = [select name,phone,AccountNumber from account limit 100];
for(account a : acc){
List<String> tempList = new List<String>();
tempList.add('account');
tempList.add(a.name);
tempList.add(a.phone);
tempList.add(a.AccountNumber );
strList.add(tempList);
}
List<contact> cList = [select name,phone,email from contact limit 100];
for(contact a : cList){
List<String> tempList = new List<String>();
tempList.add('contact');
tempList.add(a.name);
tempList.add(a.phone);
tempList.add(a.email );
strList.add(tempList);
}
return strList;
}
}
Your problem has solved Please try this code.
you can use where condition in your query only for not required field.
<apex:page controller="MixedObjectVFController" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!objectList}" var="item">
<apex:column headerValue="Object" value="{!item[0]}" />
<apex:column headerValue="Name" value="{!item[1]}" />
<apex:column headerValue="Phone" value="{!item[2]}" />
<apex:column headerValue="Email" value="{!item[3]}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
public class MixedObjectVFController {
public static List<List<String>> getObjectList(){
List<List<String>> strList = new List<List<String>>();
List<Account> acc = [select name,phone,AccountNumber from account Where Phone!=Null AND AccountNumber!=Null limit 100];
for(account a : acc){
List<String> tempList = new List<String>();
tempList.add('account');
tempList.add(a.name);
tempList.add(a.Phone);
tempList.add(a.AccountNumber );
strList.add(tempList);
}
List<contact> cList = [select name,phone,email from contact Where Phone!=Null AND Email!=Null limit 100];
for(contact a : cList){
List<String> tempList = new List<String>();
tempList.add('contact');
tempList.add(a.name);
tempList.add(a.Phone);
tempList.add(a.email );
strList.add(tempList);
}
return strList;
}
}
Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.
Thank You
Ajay Dubedi
All Answers
<apex:page controller="MixedObjectVFController" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!objectList}" var="item">
<apex:column headerValue="Object" value="{!item[0]}" />
<apex:column headerValue="Name" value="{!item[1]}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
if I want to display tempList.add(a.phone); , What should be in the VF page , I tried
<apex:column headerValue="Name" value="{!item[2]}" />
THe following messagwe is displayed
Subscript value 2 not valid. Must be between 0 and 1
Please Help.
Ikram
public class MixedObjectVFController {
public static List<List<String>> getObjectList(){
List<List<String>> strList = new List<List<String>>();
List<Account> acc = [select name,Id from account limit 100];
for(account a : acc){
List<String> tempList = new List<String>();
tempList.add('account');
tempList.add(a.name);
tempList.add(a.Id);
strList.add(tempList);
}
List<contact> cList = [select name,Id from contact limit 100];
for(contact a : cList){
List<String> tempList = new List<String>();
tempList.add('contact');
tempList.add(a.name);
tempList.add(a.Id);
strList.add(tempList);
}
return strList;
}
}
<apex:page controller="MixedObjectVFController" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!objectList}" var="item">
<apex:column headerValue="Object" value="{!item[0]}" />
<apex:column headerValue="Name" value="{!item[1]}" />
<apex:column headerValue="Id" value="{!item[2]}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Mark solved if it does help you.
Your problem has solved Please try this code.
you can use where condition in your query only for not required field.
<apex:page controller="MixedObjectVFController" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!objectList}" var="item">
<apex:column headerValue="Object" value="{!item[0]}" />
<apex:column headerValue="Name" value="{!item[1]}" />
<apex:column headerValue="Phone" value="{!item[2]}" />
<apex:column headerValue="Email" value="{!item[3]}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
public class MixedObjectVFController {
public static List<List<String>> getObjectList(){
List<List<String>> strList = new List<List<String>>();
List<Account> acc = [select name,phone,AccountNumber from account Where Phone!=Null AND AccountNumber!=Null limit 100];
for(account a : acc){
List<String> tempList = new List<String>();
tempList.add('account');
tempList.add(a.name);
tempList.add(a.Phone);
tempList.add(a.AccountNumber );
strList.add(tempList);
}
List<contact> cList = [select name,phone,email from contact Where Phone!=Null AND Email!=Null limit 100];
for(contact a : cList){
List<String> tempList = new List<String>();
tempList.add('contact');
tempList.add(a.name);
tempList.add(a.Phone);
tempList.add(a.email );
strList.add(tempList);
}
return strList;
}
}
Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.
Thank You
Ajay Dubedi
it worked.
Ikram