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

CpqAppHandler

Remote Method

deleteCartDiscount

Apex Remote Input Map

Map<String, Object> inputMap = new Map<String, Object>{
    'methodName' => 'deleteCartDiscount',
    'id' => '{DISCOUNT_ID}',
    'cartId' => '{CART_ID}',
    'price' => {BOOLEAN}
};
Map<String, Object> outputMap = new Map<String, Object>();
Map<String, Object> optionsMap = new Map<String, Object>();
CpqAppHandler handler = new CpqAppHandler();
handler.invokeMethod('deleteCartDiscount', inputMap, outputMap, optionsMap);
Parameter Type Description Required Default Value
id String Salesforce Id of the discount to be removed. Yes
cartId String Salesforce Id of the cart (Opportunity/Quote/Order) from which the discount has to be removed. Yes
price Boolean Indicates whether to run the pricing engine (true) or not (false). TRUE

Package

Communication (vlocity_cmt)

Example Request

Map<String, Object> inputMap = new Map<String, Object>{
    'methodName' => 'deleteCartDiscount',
    'id' => 'a5Txx0000004DjQEAU',
    'cartId' => '801xx000003GzLnAAK',
    'price' => true
};
Map<String, Object> outputMap = new Map<String, Object>();
Map<String, Object> optionsMap = new Map<String, Object>();
CpqAppHandler handler = new CpqAppHandler();
handler.invokeMethod('deleteCartDiscount', inputMap, outputMap, optionsMap);

Example Response

{
  "actions": {
    "itempricesupdated": {
      "client": {
        "params": {

        }
      },
      "remote": {
        "params": {
          "cartId": "801xx000003GzLnAAK",
          "price": false,
          "methodName": "getCartLineItemPrices"
        }
      },
      "rest": {
        "method": null,
        "link": null,
        "params": {

        }
      }
    },
    "itemdeleted": {
      "client": {
        "params": {
          "methodName": "getCartLineItemPrices",
          "items": [
            {
              "message": "TestDisc has been deleted from the cart.",
              "Id": "a5Txx0000004DuiEAE"
            }
          ]
        }
      },
      "remote": {
        "params": {
          "items": [
            {
              "message": "TestDisc has been deleted from the cart.",
              "Id": "a5Txx0000004DuiEAE"
            }
          ]
        }
      },
      "rest": {
        "method": null,
        "link": null,
        "params": {

        }
      }
    }
  },
  "messages": [
    {
      "message": "TestDisc has been deleted from the cart.",
      "severity": "INFO",
      "code": "200"
    }
  ]
}

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

Message Description
Action is invalid Line 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 found The CachedAPIResponse__c does not contain the '{KEY}' CacheKey for the latest and active ConfigurationSnapshotId.
CPQInvalidPriceList No Pricelist associated with the cart.
CPQUnableToDeleteOrderActivated Cannot delete discount since the Order is Activated.
Invalid account id 'CART_ID' . Empty cartId input parameter or invalid cart type.
InvalidAccountId Cart 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 already When the delete discount is being performed on a disconnected line item.
Unable to Delete Discount Discount was not deleted due to an issue.
Unable to populate selected attribute values Error while populating the Selected Attribute Values in the CartDocument.