Title: Change owner in a case insert trigger does not run from Community
Tags: trigger;community;lightning-community;guest-user
Question: I have a lightning component in a community that inserts a new case.

The case object has a before-insert trigger that changes the case ownerId.

I get an error ```INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY``` when this code runs from the community context (the community guest user).

I believe that this error is because I need read access on the User object which I cannot give the community guest user.

This is my trigger code (for an example):

```trigger Case_Trigger on Case (before insert, before update, after insert, after update) { 
    if (Trigger.isBefore &amp;&amp; Trigger.isInsert) {    
        Trigger.new[0].OwnerId= 'myUserId';
    }
}
```

Question

If there a way to give acees to the community guest user (or profile) for changing the ownerId of a case?

Comment: Then why not you are using assignment rule

Comment: Actually the case trigger is very very big with a lot of code inside. This ownership change is a very specific case which I need to change the ownership via code in the trigger

Comment: I'm afraid that you can do in same record which part of trigger.new; create a new instance like Case c = new Case(Id=trigger.new[0].Id, OwnerId='005....'); and update it. mind recursion.

Comment: But I do not want to create another case - this will trigger a lot of other stuff for me and is not something I want or need to deal with - it is not an option for me. But I do ask - this is not possible to do?

Comment: It iwll not create another case, it will update

Comment: I have tried that, I get an error: `UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record`. also I don't understand this solution - how can I update a record from within the `before insert` trigger of this record. Anyway - I cannot get this working.



{'source': 'StackExchangeDataset', 'subset': 'salesforce.stackexchange.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 6, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:08/26/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<trigger><community><lightning-community><guest-user>', 'Title': 'Change owner in a case insert trigger does not run from Community', 'ViewCount': 173, 'id': 274906, 'user_AboutMe': '', 'user_AccountId': 8706742.0, 'user_DisplayName': 'Itai Shmida', 'user_Reputation': 4849.0, 'user_Views': 603.0, 'user_id': 33798.0}}