I am a little bit new to salesforce & APEX AND need help with the following,

I want to create bulk community users & then assign them to existing accounts through APEX code/classes (for testing one of my applications)

However, I learned that to create or link a community user to an account, a contact should be available and linked to the account as well. As the user is linked to a contact directly, not account. Correct me if I am wrong.

So, how do I create new interlinked contacts & community users AND then assign them to my existing accounts, (Accounts + Contacts + Users > created using APEX)


is the sequence different: first create contact and link it to an account AND then create a user & link it to that contact?

Also, what are required fields to create a community user?

I am badly stuck, please help out and post any questions or queries for better understanding my problem. Any code or concepts etc. would be highly appreciated.

2 Answers 2


The pre-requisite to create a Community User is that you should have a Contact associated to an Account.

To allow an external user to access your community, add the user to an account as a contact record.

In your case, you will need to ensure:

  • You have an Account
  • You have created Contacts associated to that Account
  • You then create Users associated to that Contact and enabled them as Community User

For required fields, you can refer to this knowledge article. You will primarily need the associated Contact Id, and the Profile Id along with other required fields.

Refer to the linked documentations and that should provide you with more information.

  • This helps but this is only the beginning of my problem. Thanks a lot. Commented May 30, 2019 at 11:49

Please take a look at my response on this post: https://success.salesforce.com/answers?id=90630000000gxFkAAI

It may or may not help :)

You must log in to answer this question.

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