function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kora bornkora born 

Controller pages

Is it possible to have one page containing list of Accounts and list of Contacts using a standard controller ? If yes, how ? Thanks
Best Answer chosen by kora born
Ajay K DubediAjay K Dubedi
Hi Kora

It is not possible to define a VisualForce page with two entries in the standardController attribute.
I would probably create a Custom Apex Controller with a reference to both objects and action methods to handle the two different save actions you wish to run, the main reason being that you wish to show lists of objects. 
Using a standard controller + extension really just confuses things since you have a bunch of functionality you won't need specific to only a small part of the data you interacting with.
 
public class  MyController {

 public List<Obj1> listOfObjs1 {get; set;}
 public List<Obj2> listOfObjs2 {get; set;}
 public Obj1 Obj11 {get;set;}
 public Obj2 customObj22 {get;set;}

public MyController() {
    listOfObjs1 = [Select id, name from Obj1];
 }

 public PageReference saveObj1() {
   // save logic
 }
}

https://salesforce.stackexchange.com/questions/48658/how-to-use-two-standard-controllers-in-a-single-visual-force-page


Thank you
Ajay Dubedi
 

All Answers

Pradeep SinghPradeep Singh
Hi,
Yes you can have list of accounts and the list of related/child contacts on VF page using recordsetvar.

Refer below code for the same:-
<apex:page standardController="Account" recordSetVar="accounts">
    <apex:pageBlock>
        <apex:pageBlockTable value="{!accounts}" var="acc">
            <apex:column value="{!acc.name}"/>
            <apex:column>
                <apex:pageBlockTable value="{!acc.Contacts}" var="con">
                    <apex:column headerValue="Contact Name" value="{!con.name}"/>
                </apex:pageBlockTable>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>   
</apex:page>
IF you want to have separate lists then you have to use extensions with standard controller for this.
Ajay K DubediAjay K Dubedi
Hi Kora

It is not possible to define a VisualForce page with two entries in the standardController attribute.
I would probably create a Custom Apex Controller with a reference to both objects and action methods to handle the two different save actions you wish to run, the main reason being that you wish to show lists of objects. 
Using a standard controller + extension really just confuses things since you have a bunch of functionality you won't need specific to only a small part of the data you interacting with.
 
public class  MyController {

 public List<Obj1> listOfObjs1 {get; set;}
 public List<Obj2> listOfObjs2 {get; set;}
 public Obj1 Obj11 {get;set;}
 public Obj2 customObj22 {get;set;}

public MyController() {
    listOfObjs1 = [Select id, name from Obj1];
 }

 public PageReference saveObj1() {
   // save logic
 }
}

https://salesforce.stackexchange.com/questions/48658/how-to-use-two-standard-controllers-in-a-single-visual-force-page


Thank you
Ajay Dubedi
 
This was selected as the best answer
kora bornkora born
Yup - just as I guessed, thanks.