+ Start a Discussion
DineshramDineshram 

Linking Contacts to Account

All,

 

Please let me know, how do I link Contact to an Account through webservices API.

 

I am able to create contact through API, but not able to link to an Account.

 

Tried updating setContacts in Account(to existing account), after creating the contact. But, no luck.

 

Any pointers are appreciated.

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Vijay RautVijay Raut

You have to set AccountId field on Contact. Which will make sure to link contact with account.

 

As follows .... while you creating contact.

 

Contact con = new Contact();

.

.

con.AccountId = ACCOUNT_ID_VARIABLE;

.

.

 

Where you have to replace ACCOUNT_ID_VARIABLE with appropriate Account SFDC Id.

 

Hope this would help.

 

Cheers,

V.R.

All Answers

DineshramDineshram

Forgot add the following.

 

Got  INVALID_FIELD: No such column 'Contacts' on entity 'Account'., when try updating with setContacts

Vijay RautVijay Raut

You have to set AccountId field on Contact. Which will make sure to link contact with account.

 

As follows .... while you creating contact.

 

Contact con = new Contact();

.

.

con.AccountId = ACCOUNT_ID_VARIABLE;

.

.

 

Where you have to replace ACCOUNT_ID_VARIABLE with appropriate Account SFDC Id.

 

Hope this would help.

 

Cheers,

V.R.

This was selected as the best answer
DineshramDineshram
That worked. Thanks a lot.