+ Start a Discussion
Glenn WeinsteinGlenn Weinstein 

Why you might get OP_WITH_INVALID_USER_TYPE_EXCEPTION from a trigger

Posting this in order to help others who, months from now, might Google "OP_WITH_INVALID_USER_TYPE_EXCEPTION" and find this explanation.

 

We wrote an Apex trigger on the User object, to insert a custom object record anytime a user updates their Chatter status.  This was done to fulfill a client's requirement to audit all Chatter activity.

 

The trigger worked fine, until one day the client signed up some Chatter Free users.  When such a user tried to update their status, they got a pop-up with an OP_WITH_INVALID_USER_TYPE_EXCEPTION error.

 

We scratched our collective heads for awhile.  After all, Apex triggers run in "system mode," right?  That is supposed to mean that "object and field-level permissions of the current user are ignored."  And yet this trigger seemed like it was running in "user mode," enforcing restrictions based on who the current user was.

 

The root cause turned out to be that a Chatter Free user cannot be the owner of a custom object record, and SFDC by default sets the current user as a new record's first owner.  We discovered this when we realized, via experiment, that Apex triggers fired as the result of actions by Chatter Free users could definitely update an existing record, but were having problems creating records.

 

So the simple solution was to explicitly set the owner of the new record to some fully-licensed user prior to inserting it.

ShamilShamil

Glenn,

 

Thanks for sharing, this is useful to know.

Auditing Chatter statuses is a one scary feature ;)

JV100JV100

I ran into the same issue. Thanks for the post, cleared it up quickly.

pumbaapumbaa

Good to know, I ran into the same issue when external chatter user post a feeditem. Let me try your solution.

 

Thanks in advance,

Ricky

 

patrickqpatrickq
Great answer, saved a ton of time debugging something elusive. Thanks!
Douglas BeltowskiDouglas Beltowski
I am glad you took the time write this.  It certainly saved me a ton of time debugging.  Thanks!
sandeep@Salesforcesandeep@Salesforce
Please check here for more detail : 
http://salesforce.stackexchange.com/questions/23211/op-with-invalid-user-type-exception-error
Uday ShankarUday Shankar
Thanks, Great explenation.
gokul bharatigokul bharati
Thanks for sharing glen :)
Lam CorporationLam Corporation
Nice thanks Glen
Davinder Kaur 8Davinder Kaur 8
Thanks it is worth knowing ..
krishna p 28krishna p 28
Thanks for the post. I ran into same error while trying to insert a record as site guest user. Applied the solution mentioned and it solved my problem. 
Sumit Kumar Singh 9Sumit Kumar Singh 9
Useful one. Thanks for sharing!
Gupta.VishalGupta.Vishal
Glenn , thank you so much for sharing it !!!!!
Rick UptonRick Upton
Thank you, awesome to quickly find the answer I needed at the top and first click of my Google search results! I got the same error when an authenticated Customer Community user tried submitted a new case which kicked off a Process Builder process/Lightning Flow combination to create a new person account. I was confused that the form worked for unauthenticated (guest) Customer Community users but didn't for authenticated users. After I found your post I knew immediately that I had to update the Lightning Flow to create the person account by setting the owner as the same user that is used when person accounts are created for unauthenticated Customer Community users.
RahulRahul
Thanks, Nice explanation
Nisar799Nisar799

Hi All,

This post helped me also, But I am struggling with this error in my case. Here is my use case

  1. I have two custom objects A and B, A is master and B is a child. (Master-Detail relationship)
  2. I am able to set the owner of object A, and it is inserted successfully for the Chatter free user.
  3. As B is a child in the Master-Detail relationship, so I can't set the owner of B object. There is no OwnerId field available on the B object
  4. For the B it is throwing an error "System.DmlException: Insert failed. First exception on row 0; first error: OP_WITH_INVALID_USER_TYPE_EXCEPTION, Operation not valid for this user type: []"

As per salesforce documentation, it should work because of Master record's owner is the owner of all detail records in Master-Detail Relationship.

I appreciate any help on this issue.

Thank you
Nisar Ahmed