Q:

How to set the status on Order to "Activated" in Test Code

I am trying to create an order in my test code and set its Status field to "Activated". However I get FAILED_ACTIVATION, Choose a valid status and save your changes. For a new or cloned order, choose Draft. Thus I can only set it to "Draft". 
What do I need to do in order to set the status to Activated?

A:

Here's what worked for me.
1) I created the Order with a Status of "Draft".
Order order = new Order(
            Name='Test Order',
            AccountId = testAccount.Id,
            Status='Draft',
            EffectiveDate = Date.today(),
            Opportunity = testOpportunity,
            Pricebook2Id = testPricebook.Id);
insert order;

2) Next update the status and status codes.
order.StatusCode = 'A';
order.Status = 'Activated';
update order;

