+ Start a Discussion
amateur1amateur1 

how to display two query results in one table

hi 

I have two non related objects for which i have written two queries  i want to display the two query results in only one table in visual force page  how can i do that both the queries will have the same item and ware house equal that is the only relation i have

Fulfillment__c f=[select id,item__c  from Fulfillment__c where item__c=:userinput.item__c and warehouse__c=:userinput.warehouse__c ];

 

 

Goods_Received_Note_Line_Item__c grnli=[select id,item__c,warehouse__c from Goods_Received_Note_Line_Item__c where item__c=:userinput.item__c and warehouse__c=:userinput.warehouse__c

rohitsfdcrohitsfdc

Hi,

if you are using a custom controller, you can simply use a wrapper class which will return object of both types.

 

 

amateur1amateur1

can u give me sample code 

AdrianCCAdrianCC

Hello,

 

In a nutshell you need to 'package' both you objects into a single one - that's what the wrapper is for. 

public class Wrapper {
    public sObject s1;
    public sObject s2;
    
    public Wrapper(sObject s1, sObject s2) {
        this.s1 = s1;
        this.s2 = s2; 
    }
}

 

After that you'll need to create a List<Wrapper> from those 2 lists that you've retrieved on a previous step.

You'll need to expose this list from the controller to your page using {get; set;}

 

public List<Wrapper> wrapperList    {get;  set;}

 

You're gonna iterate through this list in your page using an <apex:repeat>. Access to the 2 objects will be done through the s1 and s2 properties.

 

Regards,

Adrian 

 

rohitsfdcrohitsfdc

HI,

please take a look at the following link, it may help you

 

http://force-salesforce.blogspot.in/2012/07/using-wrapper-class-for-displaying.html

amateur1amateur1

hi thats great help but can i sort them both by date

rohitsfdcrohitsfdc

Yes,

you can use "order by" keyword in your query to sort them by date. for example

 

list<account> a= [select id,name from account order by lastmodifieddate];