I have the community and logged in as a user with Customer Community user license and Customer Community User profile. There is VF page with the table that shows Contacts related to the logged in User`s Account record.

Logged in user should have the possibility to create new community users that will be assigned to the same Account record.

I am trying to create the new user with Site.createExternalUser(<user_instance>, <accoundId>) method.

It throws an Exception Site.ExternalUserCreateException: [You are already logged in.].

Is there any way on how to do that with Site class methods? I assume, that otherwise I can create Contact and then in @future method (coz of mixed DML) create the User with ContactId.

  • 1
    That future method will still run in the context of the logged in User who triggered the future call, so I believe it will still throw the same exception. developer.salesforce.com/forums/?id=906F00000009AiFIAU Dec 18, 2018 at 12:34
  • @PranayJaiswal, how could I create the user then? Expose the REST service and make a "self" callout to create the user?
    – m_konyk
    Dec 18, 2018 at 12:37

1 Answer 1


How about using Platform Events, Platform Events run in the context of the Automated Process and thus they can be used for such scenarios.

  1. Create an Event User_Creation_Event__e, with 2 fields, AccountID__C and UserJSON__C
  2. Create a Trigger on User_Creation_Event__e which will create Community users,
  3. From your COntroller , instead of calling Site.ExternalUserCreateException, just publish that event, by passing accountID and Serialized User JSOn .

Src: https://trailhead.salesforce.com/en/content/learn/modules/platform_events_basics

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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