Delete Discount from a Cart

The deleteCartDiscount is a core transactional API in Salesforce Industries CPQ that removes a discount (Account / Contract / Order Type) from a cart, then automatically re-prices the cart and re-validates it against cardinality rules.

This functionality is available only through the remote Apex entry point CpqAppHandler.deleteCartDiscount and is not exposed via any REST endpoint.

Functional Summary

  • Removes the discount line(s) referenced by the input id parameter from the cart identified by cartId.
  • Cascades re‑price & cardinality validation – invoke the pricing pipeline and the validation pipeline so recurring, one‑off and usage charges remain accurate and bundle constraints stay intact.
  • Returns a structured actions map (itempricesupdated, itemdeleted) plus messages[], enabling user‑interfaces to refresh prices and display toast notifications with no additional queries.

Preconditions

  • The cart is in an editable state (Draft/In‑Progress).
  • id belongs to a discount that is already linked to the cart.
  • Caller has Delete permission on the discount object (enforced by CRUD/FLS checks within service layer).

Post-Conditions

  • Target discount rows and dependent price adjustment records are deleted.
  • Cart price totals are recalculated and persisted.
  • Cardinality checks pass; otherwise the entire transaction rolls back.
  • Client receives actions + messages for immediate UI refresh.

Transactional Guarantees & Error Handling

  • Entire flow executes in a single Apex transaction – any unhandled exception rolls back cart changes.
  • Error payload follows the Standard Cart API schema (code, severity, message).

Apex Remote Service 

1CpqAppHandler

Remote Method 

1deleteCartDiscount

Apex Remote Input Map 

1Map<String, Object> inputMap = new Map<String, Object>{
2    'methodName' => 'deleteCartDiscount',
3    'id' => '{DISCOUNT_ID}',
4    'cartId' => '{CART_ID}',
5    'price' => {BOOLEAN}
6};
7Map<String, Object> outputMap = new Map<String, Object>();
8Map<String, Object> optionsMap = new Map<String, Object>();
9CpqAppHandler handler = new CpqAppHandler();
10handler.invokeMethod('deleteCartDiscount', inputMap, outputMap, optionsMap);
ParameterTypeDescriptionRequiredDefault Value
idStringSalesforce Id of the discount to be removed.Yes
cartIdStringSalesforce Id of the cart (Opportunity/Quote/Order) from which the discount has to be removed.Yes
priceBooleanIndicates whether to run the pricing engine (true) or not (false).TRUE

Package 

Communication (vlocity_cmt)

Example Request 

1Map<String, Object> inputMap = new Map<String, Object>{
2    'methodName' => 'deleteCartDiscount',
3    'id' => 'a5Txx0000004DjQEAU',
4    'cartId' => '801xx000003GzLnAAK',
5    'price' => true
6};
7Map<String, Object> outputMap = new Map<String, Object>();
8Map<String, Object> optionsMap = new Map<String, Object>();
9CpqAppHandler handler = new CpqAppHandler();
10handler.invokeMethod('deleteCartDiscount', inputMap, outputMap, optionsMap);

Example Response 

1{
2  "actions": {
3    "itempricesupdated": {
4      "client": {
5        "params": {
6
7        }
8      },
9      "remote": {
10        "params": {
11          "cartId": "801xx000003GzLnAAK",
12          "price": false,
13          "methodName": "getCartLineItemPrices"
14        }
15      },
16      "rest": {
17        "method": null,
18        "link": null,
19        "params": {
20
21        }
22      }
23    },
24    "itemdeleted": {
25      "client": {
26        "params": {
27          "methodName": "getCartLineItemPrices",
28          "items": [
29            {
30              "message": "TestDisc has been deleted from the cart.",
31              "Id": "a5Txx0000004DuiEAE"
32            }
33          ]
34        }
35      },
36      "remote": {
37        "params": {
38          "items": [
39            {
40              "message": "TestDisc has been deleted from the cart.",
41              "Id": "a5Txx0000004DuiEAE"
42            }
43          ]
44        }
45      },
46      "rest": {
47        "method": null,
48        "link": null,
49        "params": {
50
51        }
52      }
53    }
54  },
55  "messages": [
56    {
57      "message": "TestDisc has been deleted from the cart.",
58      "severity": "INFO",
59      "code": "200"
60    }
61  ]
62}

Response Shape

  • actions.itempricesupdated – To trigger a follow‑up call to getCartLineItemPrices so the UI can redraw totals.
  • actions.itemdeleted – Contains a client‑side toast payload indicating that the discount has been deleted from the cart.
  • messages[] – Top‑level array with readable outcome and HTTP‑style code (200 = success).

Error Messages and their Descriptions 

MessageDescription
Action is invalidLine Item action is incorrect.
Changes are not allowed because they cause updates in product(s) {PRODUCT_NAME that is read-only.If the IsChangesAllowed__c is set to False on the line item, then updating it is not allowed.
Compiled Data with key ‘{KEY}’ not foundThe CachedAPIResponse__c does not contain the ‘{KEY}’ CacheKey for the latest and active ConfigurationSnapshotId.
CPQInvalidPriceListNo Pricelist associated with the cart.
CPQUnableToDeleteOrderActivatedCannot delete discount since the Order is Activated.
Invalid account id ‘CART_ID’ .Empty cartId input parameter or invalid cart type.
InvalidAccountIdCart not associated with an Account.
Invalid attribute values found.Issue with the AttributeSelectedValues__c.
No Header Object found.Invalid Cart Id.
No product compiled data found.No data related to the product in transaction has been found in the CachedAPIResponse__c.
Not able to query - {SOBJECT}Error while performing a query on the SObject.
PricebookEntry not found for product : {PRODUCT_ID} with globalGroupKey {PRODUCT_GGK}PricebookEntry information of the product in transaction is not found in the CartDocument.
This line item has been deleted alreadyWhen the delete discount is being performed on a disconnected line item.
Unable to Delete DiscountDiscount was not deleted due to an issue.
Unable to populate selected attribute valuesError while populating the Selected Attribute Values in the CartDocument.