1

In Salesforce, there is a feature in Order Settings called 'Negative Quantities', which allows you to add OrderItems to an order with negative quantities. I am writing a script that syncs orders from an external platform, and want to represent refunded items as negative quantities.

Right now, I have something like this:

Database.Error lastDBException;
// logic to insert the orderitem and store the exception in lastDBException
if (lastDBException.getStatusCode() == System.StatusCode.FIELD_INTEGRITY_EXCEPTION
                        && lastDBException.getMessage().indexOf('negative quantities') > -1) {
    // error handling
}

This works, however it means the user has to do a sync before they hit this error. I would like to be able to check this value in a setup/installation script. I tried just doing something like

try {
    OrderItem oi = new OrderItem(Quantity = -1);
} catch ...

However, this won't work unless I create an order, associate it with an account, associate the orderitem with a product2 and pricebookentry etc. which is a very hacky fix to solve this.

I'm looking for a way to just get the value of the setting (doesn't matter if it's Apex or LWC/Aura JS code).

1 Answer 1

2

So, this is available from the MetadataAPI in object OrderSettings

enableEnhancedCommerceOrders boolean Indicates whether enhanced commerce orders are enabled for the org (true) or not (false). This preference is available only in orgs with the Salesforce Order Management license. Default value is false. Available in API versions 48.0 and later.

enableNegativeQuantity boolean Indicates whether users in the org can add order products with quantities of less than zero (true) or not (false). To enable this preference, enableOrders must be set to true.

enableOrders boolean Indicates whether orders are enabled for the org (true) or not (false). enableReductionOrders boolean Indicates whether reduction orders are enabled for the org (true) or not (false). For more information, see “Reduction Orders” in Salesforce Help. To enable this preference, enableOrders must be set to true.

enableZeroQuantity boolean Indicates whether users in the org can add order products with quantities of zero (true) or not (false). Default value is false. To enable this preference, enableOrders must be set to true.

Available in API version 42.0 and later.

You can use the Metadata API from Apex using the Apex MDAPI Wrapper

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .