I would like to allow community user to disable another community user in community Visualforce UI.

From this post: How do I deactivate a Portal User in Apex Code?, the answer suggests to set user.IsPortalEnabled as false in order to disable a user. However it gives error when I implement the code in Visualforce page's controller

public PageReference deleteUser() {
    System.debug('targetUser: '+targetUser);

    User u = [SELECT Id, Contactid, IsActive, IsPortalEnabled FROM User WHERE Id = :targetUser];
    Id contactid = u.contactid;
    u.IsActive = false;
    u.IsPortalEnabled = false;
    update u;


    String[] url = ApexPages.currentPage().getUrl().split('\\?');
    PageReference pageRef = new PageReference(url[0] + '?tab=User Management');     

    return pageRef;

It gives error when I visit the VF inside the community: Error: Update failed. First exception on row 0 with id 005S0000004hHPuIAM; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

I have tried the code with system admin account, it works. I can't understand why it doesn't work when it is called by community user. Apex code should have system level access right? I have explicitly added without sharing to the above class, it still doesn't work.

Also I understand the difference between disabling and deactivating a user. I want to disable it as I would like to delete its linked contact as well. If I comment out u.IsPortalEnabled = false;, it passes update u; but it does not allow me to remove the contact.

1 Answer 1


Partner Community profile has permission "Delegated External User Administrator" and they can create disable community users.

However, You cannot disable one community user by login other customer community user because Community profile does not provide "Manage User" or "Delegated External User Administrator" permission on profile. You can check this implementation guide for community.

Still if you want to do this, I would suggest to create a record in Custom object which will track which user needs to be disabled and then you can use scheduler which will read this record and disable community user every 1 hour.

  • Why can community user creates another community users, but cannot disable it....
    – Oscar Tang
    Commented May 5, 2015 at 3:37
  • That's good point, I have updated my answer. Commented May 5, 2015 at 3:53
  • Thank you for your prompt answer, but I still somehow don't understand. I do not have Delegated External User Administrator permission enabled as I only got community login license. However I can allow community user to create another community through Apex code. Why can't I disable community user instead? According to my understanding on your explanation, my community user should neither create nor disable other community users.
    – Oscar Tang
    Commented May 5, 2015 at 4:23
  • I have a user that does have the "Delegated External User Administrator" permission and still cannot disable partner users.
    – brezotom
    Commented May 3, 2017 at 13:43

You must log in to answer this question.

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