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

Create a test class to check record access of a specific profiles
I'm to new to apex.
I have a class that would allow Users from a public group (marketing group) to access records created by another user say "System Admin".
I wanted to create a test class that would create a record using the sys admin profile and check if the marketing group can have edit access to the record.
Here is my code:
I have a class that would allow Users from a public group (marketing group) to access records created by another user say "System Admin".
I wanted to create a test class that would create a record using the sys admin profile and check if the marketing group can have edit access to the record.
Here is my code:
public class OpportunitySharing { //sharing record after creating public void shareAfterInsert(List<Opportunity> oppoList){ OpportunityShare oppShare = new OpportunityShare(); List<Group> MarketingGroup = [SELECT Id, Name FROM Group WHERE Name = 'Marketing Group']; for(Opportunity opp: oppoList) { for(Group mg : MarketingGroup) { oppShare.OpportunityId = opp.Id; oppShare.UserOrGroupId = mg.Id; oppShare.OpportunityAccessLevel = 'Edit'; Database.SaveResult dbsr = Database.insert(oppShare, false); } } } }
If it helps please mark as correct, it may help others.
All Answers
If it helps please mark as correct, it may help others.