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
amr.rsamr.rs 

Error: Invalid field Discount for SObject OpportunityLineItem But Discount is there

Hi,

 

I'm getting this error: 

 


Error: Invalid field Discount for SObject OpportunityLineItem in creating a new VisualForce Page.

 

To be noted is Discount is already there in the Quote Line Item .

 

And the same Code works well for visualforce email Template.

 

Please help me.

 

<td><apex:OutputField value="{!line.Discount}"/></td>

kiranmutturukiranmutturu

The problem you are facing is that you are not referencing the child relationship properly. Salesforce generates a child relationship name that you need to reference in the page. For Account to Contact it is Contacts. But they are standard, trying the same for Child will not work. Salesforce asks for a relationship name when creating the lookup relationship or master detail relationship. If a name is not provided, a unique Id is generated. You can go and edit the relationship name later on. You can also check out the relationship name in Apex Explorer or Salesforce Schema browser in Eclipse. Go to the parent Object, drill down to the child relationships and you will find the relationship name.

 

Lets say, Custom_Object_1__c, I have a child object named, Custom_Object_2__c. The way to reference it is then {!Custom_Object_1__c.Custom_Object_2__r}

sparrowbradsparrowbrad

I'm still a little confused, I'm having the same problem.

 

If we are referencing the "discount" field within the Opportunity Line Items obect.....why wouldn't it follow the same format as the other fields in that object?

 

These fields are all in the same object, but only DISCOUNT is not working (see code below).....thanks

 

- Discount

- Unit Price

- Quantity

- Total Price

 

 

<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
<tr>
<td style="padding:5px">{!line.PricebookEntry.Name}</td>
<td style="padding:5px; text-align: right;">{!line.Quantity}</td>
<td style="padding:5px; text-align: right;"><apex:OutputField value="{!line.UnitPrice}"/></td>
<td style="padding:5px; text-align: right;"><apex:OutputField value="{!line.Discount}"/></td>
<td style="padding:5px; text-align: right;"><apex:OutputField value="{!line.TotalPrice}"/></td>
</tr>
</apex:repeat>