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
KaranrajKaranraj 

Opportunity line item

Hi all,

 

I have a custom object 'cust_a', which has master detail relationship with Opportunity.  When I use the custom object as Standard controller in my visual force page am not able to get the 'OpportunityLineItems'.

 

How to get the value of OpportunityLineItems?

 

Best Answer chosen by Admin (Salesforce Developers) 
goabhigogoabhigo

Ohh, declare list as:

public List<Opportunity> lstOLI {get; set;}

 

More info on access modifiers (public, private...) :

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_access_modifiers.htm

 

"By default, a method or variable is visible only to the Apexwithin the defining class. This is different from Java, where methods and variables are public by default"

All Answers

goabhigogoabhigo

Might be helpful for you:

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

 

But remember that if you are rendering page as PDF then iframe will not work.

KaranrajKaranraj

Thanks for reply.........

Am also getting same error

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

 

am rendering paga as PDF, Is there any way to solve this error?...by writting apex code like that

 

 

goabhigogoabhigo

Ahh, you can write apex class? Then there is hope :)

 

In the constructor, 

public class UrController {
 Cust_c custObj;
 List<OpportunityLineItems> lstOLI {get; set}
public UrController(ApexPages.StandardController controller) {
 custObj = (Cust__c) controller.getRecord();
 lstOLI = [select name,field1,field2... from OpportunityLineItems where Opportunity =: custObj.Opportunity__c];
}
}

 

Now use lstOLI in your VF page's repeat tag to get OpportunityLineItem..

KaranrajKaranraj

When i used your code, i got error message as OpportunityLineItem is cant used, then I used the following query to solve this error.

SELECT Amount, Id, Name, (SELECT Quantity, ListPrice,
  PricebookEntry.UnitPrice, PricebookEntry.Name
  FROM OpportunityLineItems) FROM Opportunity

 

Then in the visualforce page, i used 'lstOLI' in the repeat tag, after saving the VFpage am getting the following error

Error: Unknown property 'CustObjectA__cStandardController.$lstOLI 



goabhigogoabhigo

Please post your VF and controller code. I can assist you better..

goabhigogoabhigo

And the select statement should be something like,

lstOLI = [select name,field1,field2... from OpportunityLineItem where OpportunityId =: custObj.Opportunity__c];

KaranrajKaranraj

This is my Contoller class.....

 

public class CustomInvoiceExtension{
 Invoice__c custObj;
 List<Opportunity> lstOLI {get; set;}
public CustomInvoiceExtension()
{
}
public CustomInvoiceExtension(ApexPages.StandardController controller) {
 custObj = (Invoice__c) controller.getRecord();
 lstOLI = [SELECT Quantity, ListPrice,PricebookEntry.UnitPrice,PricebookEntry.Name FROM OpportunityLineItems Where OpportunityId =: custObj.Opportunity__c];
}
}

 

While saving am getting following error

Error: Compile Error: sObject type 'OpportunityLineItems' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 11

 

Note:-

In my VF page, am using StandardContoller as my Custom object and Extensions this Contoller

goabhigogoabhigo

Hey use:

lstOLI = [SELECT Quantity, ListPrice,PricebookEntry.UnitPrice,PricebookEntry.Name FROM OpportunityLineItem Where OpportunityId =: custObj.Opportunity__c];

 

Still same eror???

 

When they say refer WSDL just go to Setup--Develop--API--Generate Enterprise WSDL--Generate. Search for OpportunityLineItem and see the name used in database.

KaranrajKaranraj

Thanks it solved this error and now am getting error in VF page

Error: Unknown property 'Invoice__cStandardController.lstOLI'

 

<apex:page standardController="Invoice__c" extensions="CustomInvoiceExtension" showHeader="false" renderas="pdf">

...................

<apex:repeat value="{!lstOLI}" var="line">
          <tr>
             <td>{!line.OpportunityLineItems.PricebookEntry.Name}</td>
             <td>{!line.OpportunityLineItems.Description}</td>
             <td ALIGN="center"><img src='{!line.OpportunityLineItems.PricebookEntry.Product2.URL_Picture__c}'/></td>            
             <td>{!line.OpportunityLineItems.Quantity}</td>
             <td><apex:OutputField value="{!line.OpportunityLineItems.UnitPrice}"/></td>
             <td><apex:OutputField value="{!line.OpportunityLineItems.TotalPrice}"/></td>
          </tr>
       </apex:repeat> 

goabhigogoabhigo

Ohh, declare list as:

public List<Opportunity> lstOLI {get; set;}

 

More info on access modifiers (public, private...) :

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_access_modifiers.htm

 

"By default, a method or variable is visible only to the Apexwithin the defining class. This is different from Java, where methods and variables are public by default"

This was selected as the best answer
KaranrajKaranraj

Thanks a lot........It solved my issue....:smileyhappy:

Thank you once again.....

 

Where I can learn more about VFpage?Guide me to learn VFpage

goabhigogoabhigo

My pleasure karan :)

 

Search for visualforce and you will see lots of documnetations, discussion board posts. 

 

http://wiki.developerforce.com/index.php/An_Introduction_to_Visualforce

 

PDF user guide which explains almost everything about visualforce page:

http://www.salesforce.com/us/developer/docs/pages/salesforce_pages_developers_guide.pdf

 

Read, understand and practise it, that is the best method to learn. When you practise always try to understand the effect of writing each code statement. Good luck buddy.