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
Shailesh DeshpandeShailesh Deshpande 

Sharing Settings through apex code. Is this possible?

HI,

 

I have a object (Deal_Team__c) which has two lookup fields -

1. User  -- lookup to user

2. Loan  -- lookup to a custom object Loan

 

Now when i insert a record in Deal Team, i have a trigger which calls a class, that creates a new Loan Share Record based on the user id and loan id in Deal Team and grants Edit(Read/Write) permission to the user.

 

What i want is that once a user is added to the loan share object(through code or any other means) who has Read/Write access, he should be able to add other users to the loan share object for that loan record.

 

When i login as another user who is present on the loan share record(added through my code), I am unable to do this and I get an Error saying "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY".

 

So I removed the with sharing keyword on my class. This works the way i want, but the problem here is that even if the user is not added initially in the loan share, still then he is able to add himself or other users in  the loan share which should not happen.

 

Is there any way by which i can achieve this?

 

Thanks,

Shailesh.