function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
moeoomoeoo 

Create Contact object by passing existing Account object

I'm trying to create a contact object and I want to attach the existing account object.
 
The code I've written is
 

private Account m_Account = null; //Salesforce account (build-in Account object)

Contact objContact = new Contact();

objContact.FirstName = m_FirstName;

objContact.LastName = m_LastName;

objContact.Phone = m_Phone;

objContact.Account = m_Account;

After I assign the contact.Account, I'm getting following error and contact object is not created.

More than 1 field provided in an external foreign key reference in entity: Account

I hope I'm doing the right thing here. If not, is there any way I can create a Contact object using existing Account Object.

Thanks in advance

 

SuperfellSuperfell
objContact.AccountId = m_Account.Id

moeoomoeoo
Thanks a lot. It works!!:smileyvery-happy: