0

My problem is: I have made a custom lightning button that calls an apex controller to reassign a Case record to that user (change ownerId to their Id). However, the users that need to do this have Read-only access to the case (they need to stay Read only unless it is their case - done via Sharing Rules). Since they are read only when the button fires the Apex, they get the error of "insufficient permission" which is expected. My question is how do I get around the read-only permission just so the user can click the button to have apex change the ownerId field on case?

Could I do some temporary permission set and assign that via Apex?

Code is this in Apex

Public static example(String currentId) {
    Id userId = UserInfo.getUserId();
    Case c  = [SELECT Id, status, OwnerId FROM Case WHERE Id =: currentId];
    c.OwnerId = userId;
    update c;
    return c;
}
1
  • Without actually testing it, it's my understanding that you just need to make the component's controller "without sharing" (public without sharing class ExampleComponentController { ....
    – sfdcfox
    May 26, 2018 at 4:45

1 Answer 1

1

@sfdcfox is right, without sharing is the way to go:

public without sharing class TestAccess {
    @AuraEnabled
    public static Case example(String currentId) {
        Id userId = UserInfo.getUserId();
        Case c  = [SELECT Id, status, OwnerId FROM Case WHERE Id =: currentId];
        c.OwnerId = userId;
        update c;
        return c;
    }
}

You must log in to answer this question.

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