You need to sign in to do that
Don't have an account?

How to open up sharing for old/exising records in system using apex code?
I have a list of old records open and closed on which there is no sharing (these records are old requests that I want to share with groups) . How can I achieve this using apex code?
For caseShare it is CaseId, not ParentId.
obj.CaseId =c.Id;
Try the below code. It will work.
Let me know if it will work.
All Answers
You can refer the documentation here (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_accountshare.htm)
The documentation has an example in the end, do refer that for coding tips.
All share objects for custom objects are named as MyCustomObject__Share, where MyCustomObject__c is the name of the related custom object.
Go through this resource for more details on Apex sharing.
https://developer.salesforce.com/page/Using_Apex_Managed_Sharing_to_Create_Custom_Record_Sharing_Logic
I believe creating a custom code is NOT necessary. The easiest way is to create a sharing rule https://help.salesforce.com/apex/HTViewHelpDoc?id=security_sharing_cbs_about.htm&language=en_US.
Ater sharing rule is created it will recalculate sharings for existing records
Please see more details about recalculation here:
https://help.salesforce.com/apex/HTViewHelpDoc?id=security_sharing_recalculating.htm&language=en
I am trying to use this, but it throwing error at ParentId(which is the Case Id)
List<Case> CaseListToShare=new List<Case>();
CaseListToShare=[SELECT Id,CaseNumber FROM Case WHERE Id='5002800000AEIwm'];
List<CaseShare> sharesToCreate = New List<CaseShare>();
for(Case c : CaseListToShare)
{
CaseShare obj = new CaseShare();
obj.CaseAccessLevel = 'Read';
obj.ParentId =c.Id;
obj.UserOrGroupId ='0G28000001dupr';
sharesToCreate.add(obj);
}
if (!sharesToCreate.isEmpty()){
insert sharesToCreate;
system.debug('$$ sharesToCreate inserted '+sharesToCreate);
}
For caseShare it is CaseId, not ParentId.
obj.CaseId =c.Id;
Try the below code. It will work.
Let me know if it will work.
Thanks, it is working now. I am calling multiple cases and provide sharing to specific public groups based on name of group.
Should i use map to write something like this: call liost of case with id's and assign them to group if group name equal or contains name as "abc group" ?