Tuesday, October 18, 2016

Process Builder not working during record insertion and fail to launch Flow

I created Process Builder to automatically add user into Chatter group , refer to here.It works fine when I update the user but it fail when I create new user.

An error occurred at element Add_User_to_All_Chatter_Group (FlowRecordCreate).
INSERT --- INSERT FAILED --- ERRORS : (MIXED_DML_OPERATION) DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): CollaborationGroupMember, original object: User

I am assuming during creation, the user id is not yet committed, so it not able to set variable in Flow.After do some googling , I found some solution that can be applied on my case.

I also add new Record Lookup in my Flow, to check if the user already exist in Chatter group and Decision when the Lookup Result is not found.

Good thing, due to this I can remove custom field that I used to indicate if the User already added into the group.

In Process Builder , I use Scheduled Actions so I have to use  'Formula evaluates to true'.Scheduled Actions option is not available if 'Conditions are met' is ticked.In order to run this process builder as soon as possible,I choose 1 Hours Before LastModified.

After that, I create new user and there no more error.Also working fine for update.

Have a nice day.