function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion 

Apex Sharing On Case Object- Please Help!!

Hi Everyone,
    I have a profile called "Business Development". Users (who are also owners of the case) of this profile have only Read access on the 2 existing record types (lets call them A and B) of Case Object. I want users (who are also owners of the case) of this profile to have Edit access on a new case record type (lets call it C)  . So Here is the situation 

Case OWD: Private
Case Acess : A and B Record Type: Read Only- Already Exisitng Record Types
                     C record Type : Read Write : New Record Type.

Now to grant Access only to C record Type I wrote an apex class., it is given below:

    public static void determineFDMCaseOwnersAccess(List<Case> newFDMCasesBD) {
        List<Id> OwnerIdList=new List<Id>();
        Map<Id,Id> UserMap=new Map<Id,Id>();
        List<CaseShare> CaseShareRecordList  = new List<CaseShare>();
        CaseShare CaseShareRecord=new CaseShare();
        for(Case css:newFDMCasesBD){
        List <User> UserList=[Select Id,ProfileId from User where Id IN:OwnerIdList AND ProfileId=:'00eG0000000FnxC'];
        for(User uss:UserList){
        for(Case css:newFDMCasesBD){
            if(UserMap.get(css.OwnerId)!=null && css.RecordTypeId==Label.Case_Record_Type_FDM){
              CaseShareRecord=new CaseShare();
              CaseShareRecord.RowCause ='Owner';
            Database.SaveResult[] lsr = Database.insert(CaseShareRecordList,false);

This code works well and inserts CaseShare records , but on querying them it turns out that their access level is All, instead of Edit as given in the code. Also Users are unable to edit the case even post Case Share record creation. 

Is it because the sharing is being done by the case owner itself? Why cant user edit the records if he/she has CaseShare with All as access level?

Please help me with this!!!

Shrey Tyagi

Administrador TI 7Administrador TI 7
You´re not inserting(DML) the CaseShare record, the one that you see is de default created with record creation. After that you might come with Insufficent Access issues,heres where Im trying to find a solution.