You need to sign in to do that
Don't have an account?
Sammy7
getAccount () method to return multiple queries or set?
Hi,
So Im trying to display a custom visualforce page to list three separate accounts (by id and name) and their related contacts list by using a custom controller below.
But I dont know how to get accounts for Acme2 and Acme3 in the class using the same method. Any help is appreciated. Thanks.
and this is my visualpage:
So Im trying to display a custom visualforce page to list three separate accounts (by id and name) and their related contacts list by using a custom controller below.
But I dont know how to get accounts for Acme2 and Acme3 in the class using the same method. Any help is appreciated. Thanks.
public class MyController { public String getName() { return 'MyController'; } public Account getAccount() { return [SELECT id from Account where Name = 'Acme']; } }
and this is my visualpage:
<apex:page controller="MyController" tabStyle="Account"> <apex:pageBlock title="Acme"> <apex:relatedList subject="{!account}" list="Contacts"/> </apex:pageBlock> <apex:pageBlock title="Acme2"> <apex:relatedList subject="{!account}" list="Contacts"/> </apex:pageBlock> <apex:pageBlock title="Acme3"> <apex:relatedList subject="{!account}" list="Contacts"/> </apex:pageBlock> </apex:page>
You need to query all three accounts and add them to a list and then use apex:repeat to get the related list.
Please see below a sample code
All Answers
You need to query all three accounts and add them to a list and then use apex:repeat to get the related list.
Please see below a sample code
List <Account> acc List;
acc.add [SELECT id from Account where Name = 'Acme'];
acc.add [SELECT id from Account where Name = 'Acme2'];
acc.add [SELECT id from Account where Name = 'Acme3'];
Will this work?
Yes that would work but thats a bad practice as you are using 3 SOQL instead of 1. A better solution would be
List<Account> accList;
accList = [Select Id from Account where Name = 'Acme' OR Name = 'Acme2' OR Name = 'Acme3'];
Please mark the thread as solved if this answers your query.