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
MVB DeveloperMVB Developer 

Create AccountContactRelations with REST-API

Hello,

I have implemented an integration through the REST-API and I'm able to “get”, “create” and “update” Account and Contact through the REST API.

The only thing I don’t know how to handle is the AccountContactRelations object. I think the “get” should work correctly using for example an URL “sobjects/Account/0012X000021VVYVQA4/AccountContactRelations/”  and I think my implementation is working correctly.  
But I don’t know how to create one through the REST-API.

Is
 chapter in the developer documentation https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_relationships.htm (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_relationships.htm" style="color:#0563c1; text-decoration:underline" target="_blank" title="https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_relationships.htm) for this kind of object?

Best Regards
Bernhard Maehr

Best Answer chosen by MVB Developer
Gaurav Sharma 472Gaurav Sharma 472
you need a POST Request to create record.

/services/data/v48.0/sobjects/AccountContactRelation


Request body   :
---------------------------------------------------------------
{
"AccountId" : "your_acc_id" ,

"Contactid" : "your_con_id" 
}

-------------------------------------
 

All Answers

SwethaSwetha (Salesforce Developers) 
HI Bernhard,

Can you try GET with something like /services/data/v39.0/sobjects/AccountContactRelation/SourceId__c/ABCD
{"Account":{"SourceId__c":"AB"},"Contact":{"SourceId__c":"XY"}}  

Let me know if this works.Thanks
MVB DeveloperMVB Developer

Hello Swetha,

I'm not sure if I understand you right but I was not able to make it work.

First thing: Is really GET used to create the relation?
Is SourceId__c a constant value or do I need to replace it for example with the id of the Account?
And what is ABCD?

As far as I understood your post {"Account":{"SourceId__c":"AB"},"Contact":{"SourceId__c":"XY"}} is the answer of the GET request.


If I try /services/data/v39.0/sobjects/AccountContactRelation/ or /services/data/v39.0/sobjects/AccountContactRelations/ in workbench I get "Service not found"

 

 

Gaurav Sharma 472Gaurav Sharma 472
you need a POST Request to create record.

/services/data/v48.0/sobjects/AccountContactRelation


Request body   :
---------------------------------------------------------------
{
"AccountId" : "your_acc_id" ,

"Contactid" : "your_con_id" 
}

-------------------------------------
 
This was selected as the best answer
MVB DeveloperMVB Developer

@Gaurav:

Service not found at: /services/data/v48.0/sobjects/AccountContactRelation

Gaurav Sharma 472Gaurav Sharma 472
are you using post?
 
Gaurav Sharma 472Gaurav Sharma 472
CAN YOU PLEASE ALSO CONFIRM "Allow users to relate a contact to multiple accounts"  IS CHECKED.

GO TO SETUP -> ACCOUNT SETTINGS  -> CHECK IF THIS SETTING IS CHECKED.
MVB DeveloperMVB Developer
Thank you Gaurav, that solved it.
MVB DeveloperMVB Developer
The first answer from Gaurav (POST to /services/data/v48.0/sobjects/AccountContactRelation) was correct, even it didn't work first and I downvoted it. The setting "Allow users to relate a contact to multiple accounts" was missing and then the REST API tells you the service doesn't exist.