I am trying to automate the process whereby all profiles are given access to communities. This section when managing a community:

enter image description here

As I understand it, this is the NetworkMemberGroup object. I created some code to insert new NetworkMemberGroups, setting the NetworkId to the community and the ParentId to the profile, but when I save the class I get the message

DML not allowed on NetworkMemberGroup

But the docs say you can create() it, and when I go to the Workbench and check the object permissions, I get createable = true:

enter image description here

Do I need an extra permission to save the class? Or are the docs wrong here?


Not all objects that you can manipulate in the API can also be modified via Apex Code. For example, Custom Metadata can be updated by other means, but not in Apex Code. Similarly, you can't perform any DML on an ApexClass, even though you can manipulate code through other APIs (Tooling, Metadata). If you want to automate the process, you'll need to invent a workaround, such as calling the API via a callout.

  • Makes sense. So I could call a @RemoteAction from a button in Visualforce, return the list of NetworkMemberGroups to insert, and then use AJAX to insert the list in the callback?
    – George S.
    Jan 14 '16 at 23:59
  • @GeorgeS. That, or you can do a normal synchronous call and perform the callout from Apex Code. Either way should work.
    – sfdcfox
    Jan 15 '16 at 0:05

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.