5

I'm attempting to upsert a record to a custom object named Contact__c, I'm getting a compile error "Invalid field OwnerID for SObject Contact__c" Here's the code:

if(vault_key != null) {
    Contact__c contactup = new Contact__c();
    contactup.Vault_Key__c = contactmap.get('vault_key');
    contactup.First_Name__c = contactmap.get('first_name');
    contactup.Last_Name__c = contactmap.get('last_name');
    contactup.Street_1__c = contactmap.get('address1');
    contactup.Street_2__c = contactmap.get('address2');
    contactup.City__c = contactmap.get('city');
    contactup.State_Province__c = contactmap.get('prov_state');
    contactup.Country__c = contactmap.get('country');
    contactup.Zip_Code__c = contactmap.get('postal_cd');
    contactup.Client_Account__c = Id.valueof(Usermap.get('Client_Account'));
    contactup.OwnerID = Id.valueof(Usermap.get('Id'));
    upsert contactup;
}

Any idea why it's telling me OwnerId isn't a valid field?

6
  • Try field name of Owner. It's the Owner.ID that you're applying to it.
    – crmprogdev
    Commented Aug 23, 2015 at 22:25
  • @crmprogdev I tried Owner.ID, but that gives an error saying "Invalid foreign key relationship: Contact__c.Owner"
    – Tim
    Commented Aug 23, 2015 at 22:40
  • @Tim not owner.id just owner
    – Eric
    Commented Aug 23, 2015 at 22:52
  • @Eric Just owner also throws an invalid field error "Compile Error: Invalid field Owner for SObject Contact__c"
    – Tim
    Commented Aug 23, 2015 at 23:02
  • 2
    Is there a master-detail relationship on your Contact__c object?
    – Lance Shi
    Commented Aug 23, 2015 at 23:17

1 Answer 1

6

With the comments you answered, the reason is because your contact__c is on the detail side of a master-detail relationship. In that case, the owner of your contact__c object will be the owner of the master object, thus there is no ownerId field on contact__c. Hope this helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .