I have created a custom field on my AccountContactRelation called SurrogateId__c and I set configured it to be an External Identifier.

When I create an AccountContactRelation from an external service, a trigger performs text-extraction from the surrogate id (something like "companyIdentifier_contactIdentifier"), looks up both account and contact and set them.

This works great the first time a record with a given SurrogateId companyIdentifier_contactIdentifier is upserted, but on the second upsert my code fails:

System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, This contact already has a relationship with this company.: [ContactId]

Are external ID correclty supported by AccountContactRelation? Is there another solution to this problem?

  • Which field have you marked as external id? If its on AccountContactRelation and also marked as unique, it will not allow multiple records having same contact and account ids.
    – Raul
    Mar 12 '17 at 10:25
  • the surrogate key is marked as external id Mar 12 '17 at 10:25
  • I don't see any such field here in AccountContactRelation, to get better support you should add more detail and code as well.
    – Raul
    Mar 12 '17 at 10:39
  • I mention SurrogateId twice? Mar 12 '17 at 10:42
  • Ah I see you edited the post and added the information. That is the standard error, which means you cannot create additional relationship between same Contact and Account. In your trigger, you would need to avoid creating relationship if it already exists.
    – Raul
    Mar 12 '17 at 14:03

Upsert feature does not support for few junction objects in salesforce, AccountContactRelation object is one of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.