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
Shradheya TiwariShradheya Tiwari 

Linking contacts and Account

I am trying to create a relationship between Account and Contact, where I am linking account id with contact.
How can I achieve this?
Hi Shradheya,

Use AccountId field of contact to associate account with contact.

See the example in the below link
Shradheya TiwariShradheya Tiwari

Hi Sunny,

I tried this earlier also now also and got this error-

ERROR - Contact Error: (<class 'simple_salesforce.exceptions.SalesforceMalformedRequest'>, SalesforceMalformedRequest('https://********', 400, 'Contact', [{'message': 'The value provided for foreign key reference Account is not a nested SObject', 'errorCode': 'INVALID_FIELD'}]), <traceback object at 0x049786C0>)

Deepali KulshresthaDeepali Kulshrestha
Hi Shradheya,
Please follow the given below code and link with the help of these, you can solve your problem, it may be helpful to you.

This below code is working fine in my org:
Account acc = new Account(); ='Test07';
insert acc;

Contact con = new Contact();
con.lastName ='Test07';
con.AccountId = a.Id;
insert con;
You can follow for more information:

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Shradheya TiwariShradheya Tiwari
Thanks deepali for replying, but what I suggest is this is not pyhton code and I am using python for this.
If you got something for python please help me out.