+ Start a Discussion
Tarek SchmidtTarek Schmidt 

Error: Invalid field Discount for SObject OpportunityLineItem

Hi Guys,

i've just tried to add the discount field into a Order Visualforce.
But i get the following error Error: Invalid field Discount for SObject OpportunityLineItem

This is my Visualforce.

<table border="0" width="100%" id="table4">
<tr>
       <td bgcolor="#C0C0C0"><font face="Arial">Pos.</font></td>
    <!--   <td bgcolor="#C0C0C0"><font face="Arial">Produkt Nr.</font></td> -->
       <td bgcolor="#C0C0C0"><font face="Arial">Produkt</font></td>
       <td bgcolor="#C0C0C0"><font face="Arial">Beschreibung</font></td>
              
       <td bgcolor="#C0C0C0"><font face="Arial">Anzahl</font></td>
       <td bgcolor="#C0C0C0"><font face="Arial">Einzelpreis</font></td>
       <td bgcolor="#C0C0C0"><font face="Arial">Discount</font></td>
       <td bgcolor="#C0C0C0"><font face="Arial">Gesamt Preis</font></td>
</tr>
<tr>
<apex:variable value="{!1}" var="count"/>
       <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
          <tr>
             <td>{!FLOOR(count)} </td>
             <td>{!line.PricebookEntry.Name}</td>
             <td>{!line.Description}</td>
                          
             <td><apex:outputText value="{0, number, 0}">
              <apex:param value="{!line.Quantity}" /></apex:outputText></td>
             <td><apex:OutputField value="{!line.UnitPrice}"/></td>
             <td>{!line.discount}</td>
             <td><apex:OutputField value="{!line.TotalPrice}"/></td>
          </tr>
          <apex:variable var="count" value="{!count+ 1}"/>
       </apex:repeat>  
</tr>
<tr>
       <td bgcolor="#C0C0C0" align="right" colspan="7">
       <font face="Arial"><b>Total:</b>&nbsp;<apex:OutputField value="{!Opportunity.Amount}"/></font></td>
</tr>
</table>

We have a professional edition so there is no field level security or something like this.
Any suggestions?
Thanks in advance.
Best Answer chosen by Tarek Schmidt
Subramani_SFDCSubramani_SFDC
can you create formula field for this in opplinelitem object
Discount__c is formula field
there you should write flormula like this
product2__r.discount

note : i am not sure Discount is belong to which object...u can find and replace the product2 if some other object means

in vf page you should try like this
line.Discount__c

All Answers

Subramani_SFDCSubramani_SFDC
change like this and try once

<td>{!line.discount__c}</td>
Dino_Salesforce DeveloperDino_Salesforce Developer
Hi Tarek,

Discount field in OpportunityLineItem is not by default accessible. Before using this field in VF page you need to set the Field Accessibility & field level security.  For setting the field accessibility :
Setup -> Customize -> Opportunities -> Opportunity Product -> field -> Discount

Once you set the visibilty of this field, save ur page. 


Tarek SchmidtTarek Schmidt
The Problem is that we have a professional edition. So there are no profiles and no fieldlevel security....
Subramani_SFDCSubramani_SFDC
can you create formula field for this in opplinelitem object
Discount__c is formula field
there you should write flormula like this
product2__r.discount

note : i am not sure Discount is belong to which object...u can find and replace the product2 if some other object means

in vf page you should try like this
line.Discount__c
This was selected as the best answer
Tarek SchmidtTarek Schmidt
great idea... this works well. Thanks a lot!