About this question
I have a requirement to create sharing records for accounts. But When i try to create AccountSHare record it gives me an error DML Operation not allowed.
Here is the code
String query =' Select Id FROM Account WHERE '+String.join(whereClause,'AND'); Listaccounts = Database.query(query) ; List Any help?share = new List (); for(Account a:accounts){ AccountShare accountShare = new AccountShare(); accountShare.AccountId = a.Id; accountShare.UserOrGroupId = groupId; accountShare.AccountAccessLevel = 'Edit'; accountShare.ContactAccessLevel = 'Edit'; accountShare.OpportunityAccessLevel = 'Edit'; share.add( accountShare); } insert share;