To simplify tests with community users, I am trying to configure the default community for a specific profile.

Running this in Anonymous Apex, or trying to save my class containing the code:

insert new NetworkAffinity(NetworkId = '0DBJ00000008OXFOA2', ProfileId ='00eJ0000000QeWS');

results in:

DML operation Insert not allowed on NetworkAffinity

But the Documentation says:

Supported Calls

create(), delete(), describeSObjects(), query(), retrieve(), update(), upsert()

Special Access Rules

To work with the NetworkAffinity object, you must have View Setup or Customize Application permission.

I am a System Admin that has View Setup and Customize Application permissions. Updating an existing record didn't work either.

I never payed attention to these sections cause in general they were accurate. Am I missing something or are they just wrong in this case?

1 Answer 1


The list of functions refer to API calls, not Apex objects. There are plenty of objects that show as CRUD or so in the documentation, but will not work in Apex. Instead, you would need to query an existing record and use that in your test. Objects that are not writable in Apex are typically queryable without the use of @isTest(SeeAllData=true).

  • Thanks for your fast response, and the additional information, that makes it clear.
    – itsmebasti
    Dec 18, 2018 at 18:27

You must log in to answer this question.

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