While writing a test class I was not able to define object of type AccountContactRelation and got error like

Entity is not api accessible entity name: AccountContactRelation.

However, in apex controller I don't get this kind of error message while creating object or querying records. How can I resolve this compile fail?

1 Answer 1


Make sure you are using an API Version greater than or equal to 33.0. Any lower version will fail to compile if it references the AccountContactRelation object. Although the documentation claims this object was introduced in API Verison 37.0, it seems that the compiler will allow it a little further back. But you might as well use the most up to date version, which is currently 39.0.

Also make sure you enable the feature. Go to Setup > Account Settings and make sure this option is checked: Allow users to relate a contact to multiple accounts.

Let Users Relate a Contact to Multiple Accounts

  1. From Setup, enter Account Settings in the Quick Find box, then select Account Settings.

  2. Select Allow users to relate a contact to multiple accounts.

  3. Add the Related Contacts related list to the account page layouts that your reps use.
    Because the Related Contacts related list includes all direct contacts, you can remove the Contacts related list from your account page layouts.

    Easily see who’s a direct contact for the account when you add the Direct field to the Related Contacts related list.

  4. Add the Related Accounts related list to the contact page layouts your reps use.

    Easily see which account is the contact’s primary account when you add the Direct field to the Related Accounts related list.

  5. Decide whether you want to prevent activities from automatically rolling up to a contact’s primary account. If so, from Setup, go to the Activities Setting page and deselect Roll up activities to a contact's primary account.

  6. If you want to look at the relationships between contacts and accounts, create custom report types.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .