6

The standard Order object has a read-only checkbox/Boolean field called IsReductionOrder that is defined as:

Read-only. Determines whether an order is a reduction order. Label is Reduction Order.

I have code to create a reduction Order as follows, but it doesn't work because the IsReductionOrder fields is read-only, which is consistent with the documentation.

Order originalOrder = getExistingOriginalActivatedOrderSomehow();

Order reductionOrder = new Order(
    IsReductionOrder = true,
    OriginalOrderId = originalOrder.Id,
    Pricebook2Id = originalOrder.Pricebook2Id,
    EffectiveDate = originalOrder.EffectiveDate,
    Status = 'Draft'
    AccountId = originalOrder.AccountId,
);

insert reductionOrder;

If I remove that line, I get an error that the OriginalOrderId field can only be used with reduction Orders (FIELD_INTEGRITY_EXCEPTION, You can specify Original Order on reduction orders only.: []).

Question: How can I create a reduction Order programmatically?

Definitely need it for unit tests. I'm on Spring '14 with code that is API version 30.

  • Don't you need to create an original order first? Once you do, it appears as though you could create a reduction order in conjunction with an update to the original order. – crmprogdev Jul 2 '14 at 18:23
  • @crmprogdev - The original Order is the originalOrder variable. I added a declaration line to the code to make it clearer. – Peter Knolle Jul 2 '14 at 18:26
  • My apologies. Was probably writing my comment at the time you were making the edit. Either that or I simply missed that detail. ;) – crmprogdev Jul 2 '14 at 18:34
  • What happens if you remove IsReductionOrder = true; attempting to make it implicit that its a reduction order? – crmprogdev Jul 2 '14 at 18:38
  • @crmprogdev - If I remove that line, I get an error that the OriginalOrderId field can only be used with reduction Orders "FIELD_INTEGRITY_EXCEPTION, You can specify Original Order on reduction orders only.: []." – Peter Knolle Jul 2 '14 at 19:02
2

I noticed this popped up in the documentation at some point for OriginalOrderId: "Editable only if isReductionOrder is true." https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_order.htm

This should work as expected now:

Order reductionOrder = new Order(
IsReductionOrder = true,
OriginalOrderId = originalOrder.Id,
Pricebook2Id = originalOrder.Pricebook2Id,
EffectiveDate = originalOrder.EffectiveDate,
Status = 'Draft',
AccountId = originalOrder.AccountId);

insert reductionOrder;

//insert reduction order products here

reductionOrder.Status = 'Activated';
update reductionOrder;
| improve this answer | |
  • I've tried this and it does work. – Legolas Feb 17 '17 at 11:07
  • How can add Product to reductionOrder? – D T Jul 24 '18 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.