+ Start a Discussion
Harish DemoHarish Demo 

How can I share/lock records using Apex code

Hi everyone,

I am looking for a code and explanation to learn record sharing or locking in SF using Apex code, can someone help

Thx in advance
Best Answer chosen by Harish Demo
Manj_SFDCManj_SFDC
check if this helps you
http://blog.jeffdouglas.com/2009/11/25/programmatically-creating-sharing-rules-with-apex/

All Answers

Avishek Nanda 14Avishek Nanda 14

Hi Harish,

You can refer to this article. 
https://developer.salesforce.com/page/Using_Apex_Managed_Sharing_to_Create_Custom_Record_Sharing_Logic
 

Regards,
Avishek

Harish DemoHarish Demo
Thanks VInod , Avishek , any code with tst class to refer on contact or Account object
 
Manj_SFDCManj_SFDC
check if this helps you
http://blog.jeffdouglas.com/2009/11/25/programmatically-creating-sharing-rules-with-apex/
This was selected as the best answer
Avishek Nanda 14Avishek Nanda 14
Hi Harish,

Here is an example of Class and Test Class. 

Change the Code accordingly. 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm