I have the following and get an error on the insert:

        Order o1 = new Order(Name ='anOrder', Account = test, Status = 'Activated', EffectiveDate = date.today(), Program__c = clothing.id);
    insert o1;

The exact error is this: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Account Name:You must enter a value: []

The label for the Account is Account Name, the API name is just Account, and there is no other field it could be, with only a couple required fields at all. What might this be? I'm losing my mind over it. I know this is a very general question...will elaborate with whatever else as needed. Should be very simple...


Even though the list of standard fields on Order says that the field name is Account, the API name of the field with the label Account Name on the Order object is actually AccountId.

This is also true for most, if not all, standard lookup fields. The API name for a standard lookup to Opportunity is OpportunityId, to a Contact is ContactId, etc...

In the web interface, it appears as an account name, but in Apex it is an Id field. Thus, you need to provide the Id of your test account, and not the name, when you insert your test order.

Account test = new Account(<required fields here>);
insert test;

Order o1 = new Order(
    Name ='anOrder', 
    AccountId = test.Id, 
    Status = 'Activated', 
    EffectiveDate = date.today(), 
    Program__c = clothing.id

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.