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
Lukasz PiziakLukasz Piziak 

Visualforce Page based on two not related objects

Hi,

We have created a VF page to display records from 'Production Order' object as a pageBlock with pageBlockSections.
Is it possible to display on anothre pageBlock section within the same VF page records from different object? In my case 'Sales Orders'? I'm new to APex and Visualforce page and I will appreciate any help.

Below is my VF page Code
<apex:page standardController="SCMC__Production_Order__c" sidebar="false" showheader="true" recordSetVar="SCMC__Production_Order__c" extensions="TestExtension,TestExtension2">

<html>
<head>
<META http-equiv="refresh" content="60"/>
</head>
</html>

<apex:form >
<apex:pageBlock rendered="True" title="Production Work Orders">
<apex:pageBlockSection title="Production Orders to Fill">
<apex:pageBlockTable value="{!objlist}" style="width:1220px" var="item">
<apex:column style="width:100px" headerValue="Production Order No.">
<apex:outputLink value="/{!item.id}" target="_blank">
{!item.Name}
</apex:outputLink>
</apex:column>
<apex:column style="width:100px" value="{!item.Sales_Order_No__c}"/>
<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name"/>
<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description"/>
<apex:column style="width:100px" value="{!item.SCMC__Start_Date__c}" headerValue="Production Start Date"/>
<apex:column style="width:100px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date"/>
<apex:column style="width:100px" value="{!item.SCMC__Production_Status__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>

<apex:pageBlockSection title="Production Order in Progress">
<apex:pageBlockTable value="{!objlist2}" style="width:1220px" var="item">
<apex:column style="width:100px" headerValue="Production Order No.">
<apex:outputLink value="/{!item.id}" target="_blank">
{!item.Name}
</apex:outputLink>
</apex:column>
<apex:column style="width:100px" value="{!item.Sales_Order_No__c}"/>
<apex:column style="width:100px" value="{!item.Customer__c}" headerValue="Customer Name"/>
<apex:column style="width:200px" value="{!item.Assembly_Name__c}" headerValue="Hose Description"/>
<apex:column style="width:100px" value="{!item.Hose_Assembly_By__c}" headerValue="Technician"/>
<apex:column style="width:100px" value="{!item.SCMC__Planned_Completion_Date__c}" headerValue="Planned Completion Date"/>
<apex:column style="width:100px" value="{!item.SCMC__Production_Status__c}"/>
</apex:pageBlockTable>

</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
<apex:pageBlock rendered="True" title="Production Sales Orders">
<apex:pageBlockSection title="Production Sales Orders to Fill">
</apex:pageBlockSection>
</apex:pageBlock>

</apex:page>

Controller 1
public class TestExtension {
    public List<SCMC__Production_Order__c> objlist{get;set;}
    public TestExtension(ApexPages.StandardSetController controller) {
    objlist = [SELECT Name, Sales_Order_No__c,Customer__c, Assembly_Name__c, SCMC__Start_Date__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'Pending Pulling All Items'ORDER by SCMC__Planned_Completion_Date__c];
    }
}

Controller 2
public class TestExtension2 {
    public List<SCMC__Production_Order__c> objlist2{get;set;}
    public TestExtension2(ApexPages.StandardSetController controller) {
    objlist2 = [SELECT Name, Sales_Order_No__c, Customer__c, Assembly_Name__c,Hose_Assembly_By__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'Pulled All Items'ORDER by SCMC__Planned_Completion_Date__c];
    }
}
Best Answer chosen by Lukasz Piziak
KaranrajKaranraj
The problem in your query, you missed FROM SCMC__Sales_Order__c
 
salesOrderList = [SELECT Name, SCMC__Customer_Account__c, Type__c, SCMC__Current_Promise__c from SCMC__Sales_Order__c Where Type__c = 'Production Sales Order' Order by SCMC__Current_Promise__c];

 

All Answers

KaranrajKaranraj
Yes you can do by creating Sales order variable and assign value to it using SOQL query. Then you display the value of your variable in the visualforce page.

Please update the API name of the sales order object in the below code
public class TestExtension {
    public List<SCMC__Production_Order__c> objlist{get;set;}
    public List<Sales_Order__c> salesOrderList{get;set;} //Mention the API name of the object
    public TestExtension(ApexPages.StandardSetController controller) {
    objlist = [SELECT Name, Sales_Order_No__c,Customer__c, Assembly_Name__c, SCMC__Start_Date__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'Pending Pulling All Items'ORDER by SCMC__Planned_Completion_Date__c];
 
   //Write SOQL query fetch the sales order record and assign it here

    salesOrderList = [Select Id,Name from Sales_Order__c];

 
    }
}

Then smimilar to the variable objlist, you can display the salesOrderList variable value in the visualforce page
 
Lukasz PiziakLukasz Piziak
Hi Karanraj,

Thank you for your reply. Is that mean that I don't have to create a custom controller for VF page? And all what I need to do is modify one of my existing extension about bject3 list which is Sales order?
Lukasz PiziakLukasz Piziak
Karanraj,

I'm getting the following error: TestExtension Compile Error: unexpected token: Where at line 8 column 96

public class TestExtension {
    public List<SCMC__Production_Order__c> objlist{get;set;}
    public List<SCMC__Sales_Order__c> salesOrderList{get;set;}
    public TestExtension(ApexPages.StandardSetController controller) {
    objlist = [SELECT Name, Sales_Order_No__c,Customer__c, Assembly_Name__c, SCMC__Start_Date__c, SCMC__Planned_Completion_Date__c, SCMC__Production_Status__c
FROM SCMC__Production_Order__c Where SCMC__Production_Status__c = 'Pending Pulling All Items'ORDER by SCMC__Planned_Completion_Date__c];

    salesOrderList = [SELECT Name, SCMC__Customer_Account__c, Type__c, SCMC__Current_Promise__c Where Type__c = 'Production Sales Order' Order by SCMC__Current_Promise__c];
    }
}

Can you help me with this
KaranrajKaranraj
The problem in your query, you missed FROM SCMC__Sales_Order__c
 
salesOrderList = [SELECT Name, SCMC__Customer_Account__c, Type__c, SCMC__Current_Promise__c from SCMC__Sales_Order__c Where Type__c = 'Production Sales Order' Order by SCMC__Current_Promise__c];

 
This was selected as the best answer
Lukasz PiziakLukasz Piziak
Thank you Karanraj. It is working now.