Search code examples
salesforceapex-codevisualforceforce.com

VisualForce, Listing Two Objects on a "single" Page


I have read most tutorials and googled a lot, with no success...

Let's assume that I have Two DB objects.

I'd like to have a "single page" that lists their records side-by-side. The result will looks like a grid UI.

Is it possible at all? I know that we can have an "extension controller" that takes care of some customized controller. I'm still wondering how I can retrieve records from TWO objects in a single controller ...

Any Suggestion, please ??


Solution

  • Can you provide more details, because I don't see any complex in here.

    Controller:

    sObject obj1 {get;set;}
    sObject obj1 {get;set;}
    
    void methodName() {
     obj1 = [select ... ];
     obj2 = [select ... ];
    }
    

    Visualforce page:

    <apex:page controller="blablablaController" 
        title="blabla"
        sidebar="false"
    >
    
        <apex:pageMessage rendered="{!(errorMessage != null)}" summary="{!errorMessage}" severity="warning" strength="2" />
    
        <apex:form id="blaForm" >
    
            <apex:pageBlock mode="edit">
                <apex:pageBlockSection columns="1">
                    <apex:outputPanel >
                        <apex:outputText value="{!obj1.field1}" 
                            style="
                                font-weight:bold;
                                font-size:large;
                            "
                        />
                        <br/>
                        <apex:outputText value="{!obj2.field1}" 
                            style="
                                font-weight:bold;
                                font-size:large;
                            "
                        />
    ...
    

    and so on...

    Please, give us more information of what you are trying to achieve. Because as for me this solution is obvious.