+ Start a Discussion
abhinav gangradeabhinav gangrade 

Apex record sharing

I am working on writing apex sharing anonymous code,
for(Account abc: [select Owner, CreatedBy, LastModifiedBy from account where CALENDAR_YEAR(createddate) = 2014]

How to assign UserOrGroupId with Owner, CreatedBy, LastModifiedBy for one account record. Pls suggest.
Bhanu PartapBhanu Partap
Follow the link :
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm
APatAPat
List<AccountShare> accShareList = new List<AccountShare>();
for(Account abc: [select Owner, CreatedBy, LastModifiedBy from account where CALENDAR_YEAR(createddate) = 2014]){
AccountShare accShare = new AccountShare();  
accShare.UserOrGroupId = abc.OwnerId;
accShare.rowcause = 'Manual';
accShare.AccessLevel = 'Read';
}

//Add the above instance into the list and after for look, insert the list.

Hope this helps.