Hi guys I am trying to delete sharing rules on a custom object (say myCustOb__cj) based on if the user is a portal/community user or an internal user. If the user is a portal user then delete the sharing but if not then do nothing. Something like this:

List<myCustObj__Share> sharesToDelete = [Select Id from myCustObj__Share WHERE id in :alistofaccount AND UserOrGroupId in :listofportalusersrecordssharedwith];

I have queried and got the list of accounts/records associated with the object whose shares I want to delete but I am not sure how to get the userorgroupid of the portal users that are associated with the accounts in my list whose access needs to be deleted. I am still get a grasp of Sharing using apex. Thanks.


Well, if you have a list of Accounts you are checking already, you can query the user object with the same accountID

User[] listofportalusersrecordssharedwith = [Select ID From User Where AccountID IN :alistofaccount];
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.