I am getting compile time error while trying to assign userId
to opShare.UserOrGroupId
field. I am not sure what is wrong in it -
List<OpportunityShare> grantAccessUpsertLst = new List<OpportunityShare>();
for(String userId : userIds){
List<UserRecordAccess> userRecords = [SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId =: userId AND RecordId =: oppId];
if(userRecords.size() > 0 && !(userRecords.get(0).HasEditAccess)){
OpportunityShare opShare = new OpportunityShare();
opShare.UserOrGroupId = userId; // Error Line
opShare.OpportunityAccessLevel = ACCESS_LEVEL_EDIT;
opShare.OpportunityID = oppId;
grantAccessUpsertLst.add(opShare);
}
}
if(grantAccessUpsertLst.size() > 0)
upsert grantAccessUpsertLst;
Thanks in advance