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).