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
Surendra PeramSurendra Peram 

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ACCESS_LEVEL, : [] ?

Hi,

My code is 

TestObj__Share shareTestObj1 = new TestObj__Share();
shareTestObj1.ParentId = 'a9P1l0000008hOBEAY';
                            shareTestObj1.UserOrGroupId ='005240000044MWiAAM';
                            shareTestObj1.AccessLevel = 'All';
Insert shareTestObj1;

I am getting invalid Access error by giving the access as "All".

Can any one suggest me how we will give delete access to perticular user on perticular record. 

Thanks inadvance.

 
SEKAR RAJ.SEKAR RAJ.
Hi Surendra,
You have to give access level as "edit/read" when giving permission through the Apex class.

TestObj__Share shareTestObj1 = new TestObj__Share();
shareTestObj1.ParentId = 'a9P1l0000008hOBEAY';
                            shareTestObj1.UserOrGroupId ='005240000044MWiAAM';
                            shareTestObj1.AccessLevel = 'edit';
Insert shareTestObj1;

Valid values for Apex managed sharing are: Edit, Read.

Thanks,
SEKAR RAJ
Khan AnasKhan Anas (Salesforce Developers) 
Hi Surendra,

Greetings to you!

According to Salesforce doc (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm):

The All access level can only be used by managed sharing.

Please refer to the below link which might help you further with the above issue.

https://salesforce.stackexchange.com/questions/201245/grant-delete-access-level-on-record-using-apex-trigger

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Surendra PeramSurendra Peram
Hi Sekar Raj,
The edit access level will be give edit or Read. How can i give delete acess to specific user. Is it possible by any other way around ...?

Thanks,

 
Surendra PeramSurendra Peram

Hi Khan Anas,

I am not aware on Managed sharing. Can you please suggest me, how can i give delete access to specific user ?

In my real requirement, the users are stored in Opportunity team object. Requirement is to give the delete access to opportunity team members on custom object.

Thanks In-advance 

SEKAR RAJ.SEKAR RAJ.
Hi Surendra,
Try to query the record first and delete it.
List<Object__Share> deleteShare = [Select ParentId, UserOrGroupId from Object__Share where ParentId =:'pass Id'
                                        AND RowCause = 'Manual'];
        if(deleteShare.size() > 0)
            delete deleteShare ;

Thanks,
SEKAR RAJ
Surendra PeramSurendra Peram

Hi Sekar,
I donot want to delete the share record. I wanted to give delete permission to the specific user. How can i acheive this?
Thanks