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
NikiG22NikiG22 

Adding OpportuntiyLine Items to a custom Object

Hello -

 

I am trying to add a visualforce page to my custom object that will show the related products.

 

So my "Sales Checklist" object is housed on the opportunity, sales fills all the information out then the object is sent to a queue.

 

But to save time i want to pull in the opportunityLineItems in to the sales checklist?

 

Is this possable? I know very little visualforce.

 

This is as far as I have gotten:

 

<apex:page StandardController="Sales_Checklist__c">
<apex:relatedList list="Opportunity__r" />

<apex:pageBlock title="{!Sales_Checklist__c.Opportunity__r.Name}"/>

  <apex:dataTable value="{!Sales_Checklist__c.Opportunity__r}" var="opp" cellPadding="4" border="1">
                
           <apex:column ><apex:facet name="header">Product Name</apex:facet></apex:column>
                
                
           <apex:column><apex:facet name="header">Quantity</apex:facet></apex:column>
                
                
           <apex:column ><apex:facet name="header">Unit Price</apex:facet></apex:column>
                
              
           <apex:column ><apex:facet name="header">Total Price</apex:facet></apex:column>
  </apex:dataTable>
</apex:page>

 

 

any help would be greatlt appriciated

 

Thanks,

Niki

Best Answer chosen by Admin (Salesforce Developers) 
ColinKenworthyColinKenworthy

This problem was already solved inthis post:

http://boards.developerforce.com/t5/Visualforce-Development/Aggregate-Relationship-is-used-in-an-unsupported-complex/m-p/275441

 

it involved creating 2 VF pages and loading 1 into the other through an iframe.

All Answers

ColinKenworthyColinKenworthy

There are a few ways to define columns in VF tables:

 

Heres one

 

<apex:column headerValue="Opportunity Size" >
    <apex:outputText value="{!opp.Quantity}"/>
</apex:column>

 

another:

 

<apex:column value="{!opp.Quantity}"/>

 

 

 

NikiG22NikiG22

Thank you!

 

But i actully know how to add the columns, to the page i just cant get the "Products" (opportunityLineItems) to show up for the related opportunity

 

I need to show the Related products that where sold on the opportuntiy, I need the Name, Quantity, and Totalprice??

 

Here is my Code:

 

<apex:page StandardController="Sales_Checklist__c" id="productList">
<apex:form >
<apex:pageBlock >

<apex:pageBlockTable value="{!Sales_Checklist__c.Opportunity__r}" var="opp" Title="Products">
<apex:column headerValue="Product Name"><apex:outputText Value="{!opp.name}"></apex:outputText></apex:column>
<apex:column headerValue="Quantity"><apex:outputText value="{!opp.name}"></apex:outputText> </apex:column>
<apex:column headerValue="Total Price"><apex:outputText Value="{!opp.name}"></apex:outputText></apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

ColinKenworthyColinKenworthy

So your Sales_Checklist has a lookup to Opportunity and Opportunity has a related list of OpportunityLineItems.

 

<apex:pageBlockTable value="{!Sales_Checklist__c.Opportunity__r}" var="opp" Title="Products">

The value for a table should be a collection/list/array of objects, not a single object (Opportunity), with the var being a shorthand pointer to an object in the collection. Perhaps it works for a single object - I've never tried.

 

 

So your table should really be for the OpportunityLineItems (not the Opportunity) so value should be like this (OpportunityLineItems is thte child relationship name)

<apex:pageBlockTable value="{!Sales_Checklist__c.Opportunity__r.OpportunityLineItems}" ...

also to make it less confusing you should change var to reflect that it is referencing an individual OpportunityLineItem.

<apex:pageBlockTable value="{!Sales_Checklist__c.Opportunity__r.OpportunityLineItems}" var="oppLineItm" Title="Products">

 

Now your table columns can display the fields on an OpportunityLineItem e.g.

<apex:column headerValue="Quantity"><apex:outputText value="{!oppLineItm.Quantity}"></apex:outputText> </apex:column>

 

 

 

 

NikiG22NikiG22

Colin Thank you so much for your help!

 

So i made the changes you noted: But now i get the following error?

 

ErrorError: Invalid field name for SObject OpportunityLineItem

 

 

<apex:page StandardController="Sales_Checklist__c" id="ProductList">
<apex:form >
<apex:pageBlock >

<apex:pageBlockTable value="{!Sales_Checklist__c.Opportunity__r.OpportunityLineItems}" var="oppLineItm" Title="Products">

<apex:column headerValue="Product Name"><apex:outputText Value="{!oppLineItm.name}"></apex:outputText></apex:column>
<apex:column headerValue="Quantity"><apex:outputText value="{!oppLineItm.name}"></apex:outputText> </apex:column>
<apex:column headerValue="Total Price"><apex:outputText Value="{!oppLineItm.name}"></apex:outputText></apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

NikiG22NikiG22

Ok - i took out all the fields, and just built the shell and i still get this error:

 

Error: Aggregate Relationship is used in an unsupported complex expression containing 'opportunity__r.opportunitylineitems'

 

 

<apex:page StandardController="Sales_Checklist__c" id="productList">
<apex:form >
<apex:pageBlock >

<apex:pageBlockTable value="{!Sales_Checklist__c.Opportunity__r.OpportunityLineItems}" var="oppLineItm" Title="Products">


</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

ColinKenworthyColinKenworthy

This problem was already solved inthis post:

http://boards.developerforce.com/t5/Visualforce-Development/Aggregate-Relationship-is-used-in-an-unsupported-complex/m-p/275441

 

it involved creating 2 VF pages and loading 1 into the other through an iframe.

This was selected as the best answer
NikiG22NikiG22

Thank you SOOO MUCH!!! using the Iframe worked!

 

You helped me soo much!:smileyvery-happy:

Niki

ColinKenworthyColinKenworthy

I guess for the benefit of others reading this at some point in the future

 

Page 1

 

<apex:page StandardController="Sales_Checklist__c">
<apex:form >
<apex:pageBlock title="{!Sales_Checklist__c.Name}" >

<apex:pageBlockSection>
<apex:outputField value="{!Sales_Checklist__c.Name}"/>
<apex:outputField value="{!Sales_Checklist__c.OwnerId}"/>
<apex:outputField value="{!Sales_Checklist__c.CreatedDate}"/>
<apex:outputField value="{!Sales_Checklist__c.LastModifiedDate}"/>
</apex:pageBlockSection>

<apex:pageBlockSection columns="1">
<apex:iframe src="/apex/OppLines?id={!Sales_Checklist__c.Opportunity__c}" />
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

and a second page (OppLines)

 

<apex:page StandardController="Opportunity" showheader="false" sidebar="false">
<apex:pageBlock title="Products">
<apex:pageBlockTable value="{!Opportunity.OpportunityLineItems}" var="oppLineItm" title="Products">
<apex:column headerValue="Prod"><apex:outputText value="{!oppLineItm.PriceBookEntry.Name}"></apex:outputText> </apex:column>
<apex:column headerValue="Quantity"><apex:outputText value="{!oppLineItm.Quantity}"></apex:outputText> </apex:column>
<apex:column headerValue="Unit Price"><apex:outputText value="{!oppLineItm.UnitPrice}"></apex:outputText> </apex:column>
<apex:column headerValue="Total Amount"><apex:outputText value="{!oppLineItm.TotalPrice}"></apex:outputText> </apex:column>
<apex:column headerValue="Description"><apex:outputText value="{!oppLineItm.Description}"></apex:outputText> </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

 

 

 

DownstairsBDownstairsB

I wouldn't call that a solution... more of a workaround really.  I don't like it.  Does anyone have a REAL solution and or explanation for this error?

eric_wceric_wc

Any one know how to get this to work in a vf email template???

 

Thanks

Eric

hamshuhamshu

Hi,

Can anyone tell how perform same thing in PDF .bec <apex:iframe> is not working in pdf format...any help

 

 

 

thanks,

jaba

 

GoForceGoGoForceGo

I was trying to create a pdf attachment to VF email template. The iframe approach does not work. I  created a custom component that has Apex code (SOQL query) to get the child records.

 

GaryRaifeGaryRaife

Any chance you could share how you did this?

 

Im trying to get all the quote line items displayed on a custom object that has a lookup field to the orginial quote.

 

Basically , I am trying to create an invoice using a new object from the orignial quote showing the line item content.

 

But this is apparently not possible in professional edition as i am trying to cross two relationships !

 

Thanks