We are trying to implement Just-in-Time Provisioning for Communities using custom handler class. There are 3 scenarios

  1. When Contact with the provided email (Federation ID) exist in salesforce and user does not exist:- It creates community user ( links existing contact to user as well, since it is community user which is being inserted ) and login to community successfully.
  2. When user with the provided email (Federation ID) exist, it simply login to community successfully.

* 3. * When both contact and user do not exist in salesforce, we first inserts a contact and we sets attributes of user like email, last name etc. Insertion of user is automatically taken care by Auth.SamlJitHandler interface's createUser() method, but issue is we are getting MIXED_DML_ERROR due to insertion contact and user in a single transaction.

Ideally Auth.SamlJitHandler interface should have taken of this issue but seems its not working. Did anyone faced similar issue and was able to resolve. It might be possible we are missing some setting or anything in code.

Any help is highly appreciated.Thanks in advance.

  • 1
    Do you have a Role Id specified on the User?
    – Jayant Das
    May 10, 2019 at 14:48
  • Yes Jayant. We have raised a case to salesforce, Meanwhile exploring possible root cause. May 12, 2019 at 11:18
  • 1
    If you specify a role id, it won’t work. Do you need to specify one?
    – Jayant Das
    May 12, 2019 at 16:45
  • Hey Jayant, You are right, after removing role id, it works like a charm. Can you please tell why salesforce is having this behavior? Is it because of sharing of records on the fly based on the role provided, so salesforce prevents it I was following documentation provided by salesforce, here also they are setting up role id developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… Please post your solution in answer so that I can mark it as right answer. Thanks a lot for help. Much Appreciated!!! May 14, 2019 at 6:07
  • I think we can specify role only for internal users and community user's role is taken dynamically Account.Name+'Community User'. May 14, 2019 at 6:14

1 Answer 1


Per sObjects That Cannot Be Used Together in DML Operations docs, if you are trying to insert a User specified with UserRoleId, you won't be able to do so.

You can insert a user in a transaction with other sObjects in Apex code saved using Salesforce API version 15.0 and later if UserRoleId is specified as null.

As in your case, you had the Role specified for the Community Users, you won't be able to insert the User. If you don't specify a Role for a Community User, once the User is created, the Role is automatically populated based on the related Account.

  • Thanks Jayant !!! May 15, 2019 at 8:45

You must log in to answer this question.

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