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
Mark Kh09Mark Kh09 

Visualforce - Order and Order Product on one page

I am not satisfied with how the printable view comes up for Order records.  I'm trying to create a somewhat customer-presentable PDF of an Order along with the Order Products (OrderItem).

I have gone to the Appexchange to look for free products to see if there's a solution that will enable me to configure the output but have had no luck.

Visualforce seems like the only option.  To my dismay, the "relatedList" does not work since the relationship between Order and Order Product is a lookup and not a master-detail.

How can I get Order and Order Products to render on 1 page and be able to configure the output (doesn't have to be a work of art) so I can have it presentable to customers?
AnudeepAnudeep (Salesforce Developers) 
Hi Mark, 

You can do it through Visualforce and a controller. Your SOQL query should include both the orders and order products
 
List<String> productNames = new List<String>();
for(order ord:[SELECT Id,name,(select Id,
       OrderId,   
       OrderItemNumber,
       PricebookEntry.Product2.Name,
       PricebookEntry.Product2.id,
       Quantity,
       UnitPrice
       FROM OrderItems ) from order where id='801280000000PTy']){
           for(OrderItem oi : ord.orderItems){
               productNames.add(oi.PricebookEntry.Product2.name);
           }    
}
System.debug(productNames);

To construct a VF page, I suggest reviewing this post

Let me know if this helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!
 
Mark Kh09Mark Kh09
Thank you.  So what you're showing me in your reply is a sample of a custom controller I need to create and the link is a sample of a VF page, right?  I'll have to try and put everything together and see if I can construct it.