For a visualforce page, in my constructor i'm assigning a variable and retrieving an account from an associated opportunity - when I do a system.debug I get the details I want:
myObject__c myObject = [SELECT etc... ];
System.debug(myObject.opportunity__r.account);
Output:
Account:{Name=Traffic, BillingStreet=Example 34, BillingCity=Example, BillingCountry=Example, BillingPostalCode=D-80807, Website=www.google.com, Id=003N000000iTbKxXXX, CurrencyIsoCode=USD}
But, when I try to save a contact using a save function, and assign this account, the contact is saved, but it doesn't have any account saved to it.
Contact newContact = new Contact();
newContact.FirstName = contactFirstName;
newContact.LastName = contactLastName;
newContact.Title = contactJobTitle;
newContact.Email = contactEmail;
newContact.Phone = contactPhone;
newContact.Account = myObject.opportunity__r.account;
newContact.event__c = myObject.opportunity__r.expo__r.show__c;
insert newContact;
Everything else is assigned but there is nothing for account, but when I debug the same variable, it displays the required information. Why is this happening?