The standard Order object has a Status picklist field defined as follows:
Picklist of values that indicate order status. Each value is within one of two status categories defined in StatusCode. For example, the status picklist might contain Draft, Ready for Review, and Ready for Activation values with a StatusCode of Draft.
There is also a StatusCode (Status Category) field defined as follows:
The status category for the order. An order can be either Draft or Activated. Label is Status Category.
Each Status is categorized as being a Draft status or an Activated status. (This is similar to Opportunity Stages being classified as Won / Closed (IsWon).)
The documentation states that the Order can be activated by setting the Status field to an Activated state:
The application can subsequently activate an order by updating it and setting the value in its Status field to an Activated state; however, the Status field is the only field you can update when activating the order.
How can I programmatically determine if a Status picklist entry value is an Activated or Draft Status, so that I can use it to activate the order?
I do not want to do something that requires referencing the status String such as the following since it is not super robust or portable.
order.Status = 'Activated';
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
There is no way to programmatically get a specific status that is has a Status Category (StatusCode) of Activated (‘A’) or Draft (‘D’).
If you don’t care about the specific status but just that you are assigning an Activated or Draft status then there is a hack that you can implement (a co-worker of mine came up with).
The hack is to iterate over the picklist values from the Order.Status field’s describe and assign them to dummy Orders, insert the Orders with Database.insert(dummyOrders, false).. The ones that insert successfully will be ‘D’raft StatusCodes since you can only insert Orders with a Draft status. The ones that fail will be ‘A’ctivated statuses.
It is a hack for sure, but has worked for us in our unit tests when we need to create an Order in a Draft status or Activate an Order as part of a unit test and don’t want to use hardcoded values, custom labels, etc.
It would appear that that data isn’t currently available, at least it’s not in the latest object reference where i could find it.
For most objects with special picklists there is a corresponding object you can use to query the values with their related metadata. For example the
ContractStatus object stores the
StatusCode of Draft, InApproval, Activated for each picklist value.
You might just try
OrderStatus and see if that works, otherwise I’d recommend contacting support to see about when that object will be available.