0

Currently I am trying to share a record manually using Lightning components. As a owner

  1. Admin is able to share a record with User A
  2. User A is not able to share a record with User B

Our requirement is to share a record irrespective of Admin or Permission all access rights.

Here is the class which checks for logged in User permission set. But I am getting an error saying :

Insufficient access rights on Cross Reference

Not sure is this a issue with my code or am i missing some permissions to be given to the users or on objects

global with sharing class LightningSharing {
    global class SharingPermsException extends Exception{}
    @AuraEnabled
    global static boolean canIEditPerms(id recordId){
        try {

        /*Sample Query
        SELECT RecordId, MaxAccessLevel, HasAllAccess, HasDeleteAccess, HasEditAccess, HasReadAccess, HasTransferAccess FROM UserRecordAccess where UserId = '00550000000rlrX' and RecordId IN ('0015000000TaWdI','0065000000N1CMz')*/
            UserRecordAccess accessList = [ SELECT RecordId,HasAllAccess, 
                                                     HasDeleteAccess, 
                                                     HasEditAccess,
                                                     HasReadAccess, 
                                                     HasTransferAccess FROM UserRecordAccess WHERE UserId =: userInfo.getUserID() AND RecordId =: recordId];
          system.debug('Debug stateemnt 1'+accessList);

            if(accessList.HasEditAccess == true)

            return true;

        } catch (system.queryException e){
            //it's possible you can't even see that record and the queries are null!
            return false;
        }
        return false;
    }

I changed the code to include a new class withoutsharing scope and here is the code

global without sharing class LightningSharingCustom {

global class SharingPermsException extends Exception{}

@AuraEnabled
global static boolean canIEditPerms(id recordId){
try {

/*Sample Query
SELECT RecordId, MaxAccessLevel, HasAllAccess, HasDeleteAccess, HasEditAccess, HasReadAccess, HasTransferAccess FROM UserRecordAccess where UserId = '00550000000rlrX' and RecordId IN ('0015000000TaWdI','0065000000N1CMz')*/
UserRecordAccess accessList = [ SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId =: userInfo.getUserID() AND RecordId =: recordId];
 system.debug('Debug stateemnt 1'+accessList);

            if(accessList.HasEditAccess == true)

   return true;

} catch (system.queryException e){
//it's possible you can't even see that record and the queries are null!
return false;
}
return false;
}

Still code fails to execute. Share button itslef doesnt work.

3
  • Is it because class is running with "with sharing"? – Jai Chaturvedi Aug 31 '17 at 23:56
  • yes. it is because of sharing – Sneha Sep 4 '17 at 13:51
  • try changing this signature global with sharing class LightningSharing to global without sharing class LightningSharing , as you are using the class with sharing this will mind current user permission to execute and process the code so this will throw error such as insufficient rights. so It is advicible to use without sharing class . – Rahul Mar 4 '20 at 20:41
0

If you want to configure the visibility on this particular class, you may remove the "With Sharing" keyword. What will happen is it will run on system context then you can decide the visibility of the field by yourself. Of you could use "Without Sharing" so it wouldn't honor the OWD settings. Please see: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm?search_text=with%20sharing

3
  • I have made changes to the code. – Sneha Sep 4 '17 at 13:52
  • but still i am getting the error – Sneha Sep 4 '17 at 13:53
  • i have included both the code in my question.. – Sneha Sep 4 '17 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.