In apex class, i was writing in dev console --> order.ownerid=opportunity.ownerid; But I was getting Invalid field ownerid for SObject Order. Can anyone tell me why ownerid is invalid for order?

  • 1
    Checking owd sharing. If set to public read/write ownerid will not be available – Eric Jun 14 '17 at 3:14

You got this is error because the relationship between Order and Opportunity object is Master-Detail..In this case Order object is on detail side of master detail relationship hence the owner of Order object is master of Order object hence you get an error that Invalid field ownerid for SObject Order.

| improve this answer | |
  • Please stop signing your posts. Every post you make is already “signed” with your standard user card, which links directly back to your user page. If you use an additional signature or tagline, it will be removed to reduce noise in the questions and answers. -What kind of behavior is expected of users? – Adrian Larson Jun 14 '17 at 11:17

First Check owd sharing. If set to public read/write ownerid will not be available.

It's Working at my end,here is sample code

public class Test {

public static void test()
    Opportunity Opp=[select id,Name,ownerId from Opportunity where Name='fasdfasdf'];
    Order order=[select id,OrderNumber,ownerId from Order where OrderNumber='00000100'];


| improve this answer | |

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.