OpportunityLineItem
Represents an opportunity line item, which is a member of the list of Product2 products associated with an Opportunity.
create(), delete(), describeLayout(), describeSObjects(), getDeleted(), getUpdated(), query(), retrieve(), update(), upsert()
- The user must have the “Edit” permission on Opportunity records to create or update opportunity line items on an opportunity.
-
Type: reference
-
Properties: Create, Filter, Group, Nillable, Sort, Update
-
Introduced: API version 64.0
-
Relationship name: Asset
-
Relationship type: relationship
-
Refers to: Asset
- Type: boolean
- Properties: Defaulted on create, Filter, Group, Sort
- Introduced: API version 43.0
- Description: Indicates whether the opportunity product can have a quantity schedule (
true) or not (false). This field is read-only. - Default value: false
- Type: boolean
- Properties: Defaulted on create, Filter, Group, Sort
- Introduced: API version 43.0
- Description: Indicates whether the opportunity product can have a revenue schedule (
true) or not (false). This field is read-only. - Default value: false
- Type: reference
- Properties: Filter, Group, Nillable, Sort
- Introduced: API version 14.0
- Description: ID of the PartnerNetworkConnection that shared this record with your organization. This field is available if you enabled Salesforce to Salesforce.
- Relationship name: ConnectionReceived
- Relationship type: relationship
- Refers to: PartnerNetworkConnection
- Type: reference
- Properties: Filter, Group, Nillable, Sort
- Introduced: API version 14.0
- Description: ID of the PartnerNetworkConnection that you shared this record with. This field is available if you enabled Salesforce to Salesforce. This field is supported using API versions earlier than 15.0. In all other API versions, this field’s value is null. You can use the new PartnerNetworkRecordConnection object to forward records to connections.
- Relationship name: ConnectionSent
- Relationship type: relationship
- Refers to: PartnerNetworkConnection
- Type: string
- Properties: Create, Filter, Group, Nillable, Sort, Update
- Description: Text description of the opportunity line item. Limit: 255 characters.
-
Type: percent
-
Properties: Create, Filter, Nillable, Sort, Update
-
Introduced: API version 18.0
-
Description:
Discount for the product as a percentage.
When updating these records:
- If you specify
Discountwithout specifyingTotalPrice, theTotalPriceis adjusted to accommodate the newDiscountvalue, and theUnitPriceis held constant. - If you specify both
DiscountandQuantity, you must also specify eitherTotalPriceorUnitPriceso the system knows which one to automatically adjust.
- If you specify
- Type: boolean
- Properties: Defaulted on create, Filter, Group, Sort
- Description: Read-only. Indicates whether a quantity schedule has been created for this object (
true) or not (false). - Default value: false
-
Type: boolean
-
Properties: Defaulted on create, Filter, Group, Sort
-
Description:
Indicates whether a revenue schedule has been created for this object (
true) or not (false).If this object has a revenue schedule, the
QuantityandTotalPricefields can’t be updated. In addition, theQuantityfield can’t be updated if this object has a quantity schedule. Update requests aren’t rejected but the updated values are ignored. -
Default value: false
- Type: boolean
- Properties: Defaulted on create, Filter, Group, Sort
- Description: If either
HasQuantityScheduleorHasRevenueScheduleistrue, this field is alsotrue. - Default value: false
- Type: datetime
- Properties: Filter, Nillable, Sort
- Introduced: API version 68.0
- Description: The timestamp when the current user last synced this record.
- Type: currency
- Properties: Filter, Nillable, Sort
- Description: Corresponds to the
UnitPriceon the PricebookEntry that is associated with this line item, which can be in the standard price book or a custom price book. A client application can use this information to show whether the unit price (or sales price) of the line item differs from the price book entry list price.
- Type: string
- Properties: Filter, Nillable, Sort
- Introduced: API version 30.0
- Description: The opportunity line item name (known as “Opportunity Product” in the user interface). This read-only field is available in API version 30.0 and later.
- Type: currency
- Properties: Filter, Nillable, Sort
- Introduced: API version 56.0
-
Type: reference
-
Properties: Create, Filter, Group, Sort
-
Description:
Required. ID of the associated Opportunity.
This is a relationship field.
-
Relationship name: Opportunity
-
Relationship type: relationship
-
Refers to: Opportunity
-
Type: reference
-
Properties: Create, Filter, Group, Nillable, Sort
-
Introduced: API version 2.0
-
Description:
Required. ID of the associated PricebookEntry. Exists only for those organizations that have Products enabled as a feature. In API versions 1.0 and 2.0, you can specify values for either this field or
ProductId, but not both. For this reason, both fields are declared nillable. In API version 3.0 and later, you must specify values for this field instead ofProductId.This is a relationship field.
-
Relationship name: PricebookEntry
-
Relationship type: relationship
-
Refers to: PricebookEntry
-
Type: reference
-
Properties: Create, Filter, Group, Nillable, Sort
-
Introduced: API version 30.0
-
Description:
The ID of the related Product2 record. This is a read-only field available in API version 30.0 and later.
Use the
PricebookEntryIdfield instead, specifying the ID of the PricebookEntry record. -
Relationship name: Product2
-
Relationship type: relationship
-
Refers to: Product2
- Type: string
- Properties: Filter, Group, Nillable, Sort
- Introduced: API version 30.0
- Description: This read-only field is available in API version 30.0 and later. It references the value in the ProductCode field of the related Product2 record.
-
Type: double
-
Properties: Create, Filter, Sort, Update
-
Description:
Read-only if this record has a quantity schedule, a revenue schedule, or both a quantity and a revenue schedule.
When updating these records:
- If you specify
Quantitywithout specifying theUnitPrice, theUnitPricevalue is adjusted to accommodate the newQuantityvalue, and theTotalPriceis held constant. - If you specify both
Discountand Quantity, you must also specify eitherTotalPriceorUnitPriceso the system can determine which one to automatically adjust.
- If you specify
- Type: boolean
- Properties: Defaulted on create, Filter, Group, Sort
- Introduced: API version 5.0
- Description: Changes behavior of OpportunityLineItem calculations when a line item has child schedule rows for the
Quantityvalue. When enabled, if the rollup quantity changes, then the quantity rollup value is multiplied against the sales price to change the total price. Product2 flag must be set to true. - Default value: false
-
Type: date
-
Properties: Create, Filter, Group, Nillable, Sort, Update
-
Description:
Date when the product revenue will be recognized and the product quantity will be shipped.
- Opportunity Close Date—
ServiceDateis ignored. - Product Date—
ServiceDateis used if notnull. - Schedule Date—
ServiceDateis used if notnulland there are no revenue schedules present for this line item, that is, there are no OpportunityLineItemSchedule records with a fieldTypevalue of Revenue that are children of this record.
- Opportunity Close Date—
- Type: int
- Properties: Create, Filter, Group, Nillable, Sort, Update
- Description: Number indicating the sort order selected by the user. Client applications can use this to match the sort order in Salesforce.
- Type: currency
- Properties: Filter, Nillable, Sort
- Introduced: API version 18.0
- Description: Difference between standard and discounted pricing. Converted currency amounts when the opportunity’s currency is different from the user’s currency.
-
Type: currency
-
Properties: Create, Defaulted on create, Filter, Nillable, Sort, Update
-
Description:
This field is available only for backward compatibility. It represents the total price of the OpportunityLineItem.
If you don’t specify
UnitPrice, this field is required. If you specifyDiscountandQuantity, this field orUnitPriceis required. When updating these records, you can change either this value or theUnitPrice, but not both at the same time.This field is nillable, but you can’t set both
TotalPriceandUnitPriceto null in the same update request. To insert theTotalPricevia the API (given only a unit price and the quantity), calculate this field as the unit price multiplied by the quantity. This field is read-only if the opportunity line item has a revenue schedule. If the opportunity line item doesn’t have a schedule or only has a quantity schedule, this field can be updated.
-
Type: currency
-
Properties: Create, Defaulted on create, Filter, Nillable, Sort, Update
-
Description:
The unit price for the opportunity line item. In the Salesforce user interface, this field’s value is calculated by dividing the total price of the opportunity line item by the quantity listed for that line item. Label is Sales Price.
This field or
TotalPriceis required. You can’t specify both.If you specify
DiscountandQuantity, this field orTotalPriceis required.
An Opportunity can have associated OpportunityLineItem records only if the Opportunity has a Pricebook2. An OpportunityLineItem must correspond to a Product2 that is listed in the opportunity’s Pricebook2. For information about inserting OpportunityLineItem for an opportunity that doesn’t have an associated Pricebook2 or any existing line items, see Effects on Opportunities.
This object is defined only for orgs with products enabled as a feature. If the products feature isn’t enabled, this object doesn’t appear in the describeGlobal() call, and you can’t use describeSObjects() or query the OpportunityLineItem object.
For a visual diagram of the relationships between OpportunityLineItem and other objects, see the Product & Price Book diagram.
- If the multicurrency option is enabled, the
CurrencyIsoCodefield is present. It can’t be modified, and is always set to the value of theCurrencyIsoCodeof the parent Opportunity. - If customizable product schedules are enabled, you can use custom fields in default schedules and customize their layout. But if you’ve applied validation rules or Apex triggers, they’re bypassed when they’re first inserted.
Opportunities with associated OpportunityLineItem records are affected in the following ways:
- Creating an OpportunityLineItem increments the Opportunity
Amountvalue by theTotalPriceof the OpportunityLineItem. Additionally, inserting an OpportunityLineItem increments theExpectedRevenueon the opportunity by theTotalPricetimes the opportunityProbability. - The Opportunity
Amountbecomes a read-only field when the opportunity has line items. The API ignores any attempt to update this field on an opportunity with line items. Update requests aren’t rejected, but the updated value is ignored. - You can’t update the
PricebookIdfield or theCurrencyIsoCodefield on the opportunity if line items exist. The API rejects any attempt to update these fields on an opportunity with line items. - When you create or update an OpportunityLineItem, the API verifies that the line item corresponds to a PricebookEntry in the Pricebook2 associated with the opportunity.
- If the opportunity has an associated active or inactive Pricebook2, the OpportunityLineItem is created or updated.
- If the opportunity doesn’t have an associated Pricebook2, but the OpportunityLineItem corresponds to a PricebookEntry in an active Pricebook2 where the PricebookEntry has a
CurrencyIsoCodevalue that matches theCurrencyIsoCodevalue of the opportunity, the API automatically sets this PriceBook2 on the opportunity. - If the opportunity doesn’t have an associated Pricebook2, but the line item corresponds to a PricebookEntry in a Pricebook2 that isn’t active or that has a
CurrencyIsoCodevalue that does not match theCurrencyIsoCodevalue of the opportunity, an error is returned.
- The Opportunity
HasOpportunityLineItemfield is set totruewhen an OpportunityLineItem is inserted for that Opportunity. - When OpportunityLineItem records are directly deleted, they aren’t sent to the recycle bin and can’t be undeleted. The
getDeleted()call shows deleted OpportunityLineItem records until they’re purged, which is usually within the same day or the next day. - In Lightning, the
ListPrice,Name, andProductCodefields aren’t populated before insert because their values are computed after the OpportunityLineItem.Product2Id value is saved. To access a value from these fields, use an After Insert trigger.
This object has the following associated objects. If the API version isn’t specified, they’re available in the same API versions as this object. Otherwise, they’re available in the specified API version.
- OpportunityLineItemChangeEvent: Introduced in API version 60.0.