Creating a Order
This API creates an order for a specific Account and Price List.
|
API |
Signature |
|---|---|
|
createOrder |
webService static Apttus_CPQApi.CPQ.CreateOrderResponseDO createOrder(Apttus_CPQApi.CPQ.CreateOrderRequestDO request) |
|
Parameters |
|||
|---|---|---|---|
|
Name |
Type |
Required? |
Description |
|
request |
|
Yes |
The request data object. |
|
Request Data Object - Apttus_CPQApi.CPQ.CreateOrderRequestDO |
||
|---|---|---|
|
Field |
Type |
Description |
|
CustomFields |
List<String> |
List of Custom fields which can be used in Order Creation. |
|
OrderInput |
Apttus_Config2__Order__c |
The Order Object |
|
OrderItems |
List<Apttus_CPQApi.CPQ.SelectedProductDO> |
List of Order Items |
|
OrderItemSource |
String |
The source from where the Order is getting created. |
|
Properties |
List<Apttus_Config2.Property> |
List of properties |
|
Response Data Object - Apttus_CPQApi.CPQ.CreateOrderResponseDO |
||
|---|---|---|
|
Field |
Type |
Description |
|
JobId |
ID |
In case of a Bulk order creation the API will return the Job ID which can be tracked. |
|
OrderId |
ID |
Order Id |
Code Sample
The code below helps to create an order from a quote. It takes a quote number as input, creates an order, and generates order line items for the respective quote line items.
/**
* The below method demonstrates how to create Order
* The input of this method is Quote Number
*/
public static void createOrder(String quoteNumber) {
// Query to retrieve proposal line items based on the provided quote number
List<Apttus_Proposal__Proposal_Line_Item__c> proposalLineItems = [
SELECT Id,
Apttus_Proposal__Proposal__r.Apttus_Proposal__Account__c,
Apttus_Proposal__Proposal__r.Apttus_QPConfig__PriceListId__c,
Apttus_Proposal__Proposal__r.Apttus_Proposal__ExpectedStartDate__c,
Apttus_Proposal__Proposal__r.Apttus_Proposal__ExpectedEndDate__c
FROM Apttus_Proposal__Proposal_Line_Item__c
WHERE Apttus_Proposal__Proposal__r.Name = :quoteNumber
AND Apttus_QPConfig__ParentBundleNumber__c = NULL
AND Apttus_QPConfig__IsPrimaryLine__c = true
];
// Initialize the order creation request object
Apttus_CPQApi.CPQ.CreateOrderRequestDO request = new Apttus_CPQApi.CPQ.CreateOrderRequestDO();
// Check if there are any proposal line items returned from the query
if (!proposalLineItems.isEmpty()) {
// Loop through each proposal line item to prepare the order items
for (Apttus_Proposal__Proposal_Line_Item__c proposalLineItem : proposalLineItems) {
// Create a selected product object for each proposal line item
Apttus_CPQApi.CPQ.SelectedProductDO selectedProduct = new Apttus_CPQApi.CPQ.SelectedProductDO();
selectedProduct.SourceId = proposalLineItem.Id; // Set the source ID
request.OrderItems.add(selectedProduct); // Add selected product to the order items
}
}
// Create the order input object
Apttus_Config2__Order__c orderInput = new Apttus_Config2__Order__c();
// Populate the order input fields with values from the first proposal line item
orderInput.Apttus_Config2__SoldToAccountId__c = proposalLineItems[0].Apttus_Proposal__Proposal__r.Apttus_Proposal__Account__c;
orderInput.Apttus_Config2__PriceListId__c = proposalLineItems[0].Apttus_Proposal__Proposal__r.Apttus_QPConfig__PriceListId__c;
orderInput.Apttus_Config2__OrderStartDate__c = proposalLineItems[0].Apttus_Proposal__Proposal__r.Apttus_Proposal__ExpectedStartDate__c;
orderInput.Apttus_Config2__OrderEndDate__c = proposalLineItems[0].Apttus_Proposal__Proposal__r.Apttus_Proposal__ExpectedEndDate__c;
// Set the order item source
request.orderItemSource = Apttus_CPQApi.CPQ.ITEMSOURCE_QUOTE_LINEITEM;
request.OrderInput = orderInput; // Attach the order input to the request
// Call the API to create the order and capture the response
Apttus_CPQApi.CPQ.CreateOrderResponseDO createOrderResponseDO = Apttus_CPQApi.CPQWebService.createOrder(request);
// Log the response for debugging purposes
System.debug('createOrderResponseDO:-- ' + createOrderResponseDO);
}
