Loading

Import Order Products with Data Loader

Date de publication: Oct 13, 2022
Description

Use the Data Loader to insert, update, or upsert Order Products in Salesforce.

Depending on experience with Data Loader, creating and manipulating CSV files, and the number of Order Products (OrderItems) you need to create - it may be more efficient to simply Add Products to an Order manually via the user interface.

The steps below are for adding Order Products to existing Orders in Salesforce.

Résolution
It's important to understand the Data Model and the object relationship between Order Product (OrderItem), Order, and PricebookEntry. See the Product and Schedule Objects documentation for a visual representation.
 

Key points:

 
  • PricebookEntry represents a product entry (an association between a Pricebook and Product) in a price book.
 
  • Orders are assigned a Price Book.
 
  • OrderItems are associated to Products via PricebookEntry records.
 
  • It's only possible to add Order Items or Products via PricebookEntry records for the Pricebook that's assigned to the Order.
 
  • It's not possible to add Products to activated Orders. If an order is activated and you attempt to add or modify its products users will encounter the following error:
'unable to modify activated order:  cannot delete order, or add or remove order products'

 

Create a CSV with the following columns (fields) for Order Product: 


ID - Optional for update or upsert, specify the existing Product Order record Ids for update. If an Id is not set for a row in your file, an upsert with Data Loader will create a new Order Product for that row.

ORDERID - record Id for the Order you're adding products to. If adding multiple Products to the same Order create an individual row for each unique Product to be added. Use Data Loader to Export Data by checking 'Show all Salesforce objects' and choosing the 'Order (Order)' object to create a list of existing Order Ids.
 

Sample export query: SELECT Id, OrderNumber, OwnerId, Owner.Name, AccountId, Account.Name, Pricebook2Id, Pricebook2.Name FROM Order WHERE Status = 'Draft'
 

Note: The query above only returns draft orders since it's not possible to add or modify products for activated orders. It is possible to change activated orders back to draft by updating the Order object's 'Status' field from a value of 'Activated' to 'Draft' via the Data Loader. See Insert, Update, or Delete Data Using Data Loader and the Order | SOAP API Developer Guide documentation for more details.
 

PRICEBOOKENTRYID - The record Id Product's entry in the Price Book that's associated to the Order. Use Data Loader to Export Data from the Price Book Entry (PriceBookEntry) object to generate a list of record Ids.
 

Sample export query: Select Name, Id, UnitPrice, Pricebook2.Name, Pricebook2Id, Product2.Name, Product2Id FROM PricebookEntry WHERE IsActive = true


QUANTITY - Required, initial or the updated number of products.

UNITPRICE - Required, unit price for the order product.

SERVICEDATE - The Start Date for the order product. For acceptable values see the 'Date Formats' section of the Data Types Supported by Data Loader for more details.


Note: You may need to add additional fields depending on your org's unique customizations such as validation rules or required fields on the Order Product object. Refer to the OrderItem documentation for standard fields.
 

Populate your CSV file:


1. Populate the corresponding Order Ids for which you would like to add or update Products into the ORDERID column.

2. Populate PricebookEntry Ids and Unit Price values into your file.

3. Populate the Quantity you wish to have for your line items.

4. Put the Service Dates in with the appropriate Line Items or Orders. (Dependent on your Business Logic this is Org and company specific)

5. (Optional for upsert) populate existing Order Product (line item) record Ids.

6. (Optional for upsert) edit the Service Date or Quantity for the established Line Items.  If you do not make changes to the line item you will receive Errors in Data Loader. If you are not making changes to the line items, you can remove or exclude them from the CSV.

 

Use Data Loader and select IInsert to create new or Upsert to create new and update existing Order Products.


1. Check the box for 'Show all Salesforce objects'

2. Select "Order Product (OrderItem)"

3. Choose the CSV you created and Next.

4. Hit next again (For Upsert, map the Id column from the CSV as the default Matching Field for Data Loader Step 2a).

5. Create a Mapping, Auto-Match Fields to Columns, click OK, and click Next.

6.  Click the Browse... button to select the directory where the success and error files should be saved, then click "Finish".

7. When a pop appears asking you to proceed, click Yes.

 

See Also:

Data Loader Overview
Orders Overview
Preparing Your Data for Import

Prepare a CSV file for an import or update in Salesforce

Numéro d’article de la base de connaissances

000384893

 
Chargement
Salesforce Help | Article