I'm trying to create a test class for this operation:
List<UserTeamMember> listUserTeamMember = [Select id, ownerId, TeamMemberRole, OpportunityAccessLevel, userId from UserTeamMember where OwnerId =: mapOutboundUserInboundUser.values()];
mapIdOutboundUser = new Map<Id,User>([SELECT id, Network__c FROM User WHERE Id IN: mapOutboundUserInboundUser.values()]);
for(UserTeamMember utm : listUserTeamMember){
if(mapInboundUserAccTeam.get(utm.ownerId) == null){
List<UserTeamMember> listatm = new List<UserTeamMember>();
listatm.add(utm);
mapInboundUserAccTeam.put(utm.ownerId, listatm);
}else{
mapInboundUserAccTeam.put(utm.ownerId, (List<UserTeamMember>) mapInboundUserAccTeam.get(utm.ownerId).add(utm));
}
}
Where mapOutboundUserInboundUser is just a map of outbound users that will be replaced with Inbound users. After that the map filled in the first code sample it is used like below.
if(mapInboundUserAccTeam.get(incomingUser) != null){
for(UserTeamMember utm : mapInboundUserAccTeam.get(incomingUser)){
OpportunityTeamMember oppTM = new OpportunityTeamMember(OpportunityId = opp.Id, TeamMemberRole = utm.TeamMemberRole, OpportunityAccessLevel = utm.OpportunityAccessLevel, UserId = utm.userId);
listUserOppTeamMemberToadd.add(oppTM);
}
}
The aim of the process is to change ownership of an opportunity and Also change the opportunityTeamMembers associated with that opportunity depending on the UserTeamMember of the incoming users
In my test class i'm querying a user from the object UserTeamMember. My goal is to get a user that have UserTeamMember so I can test my class above. I do as follow:
Id idUserOppTest = [SELECT Id, OwnerId FROM UserTeamMember LIMIT 1].OwnerId;
It works nice when i'm on a test org, as we do have some Users with UserTeamMember.
My problem is that we do have a process where our code is deployed on a blank scratch org using a pipeline. When this test class is executed on that blank scratch the request above return no results. As this scratch has no user with UserTeamMember linked to it.
I did try inserting the UserTeamMember but it does not allow insert DML.
How could I create a user with a UserTeamMember inside my test class? So it can be executed on any orgs?
Thanks in advance.
force:data:record:create
to create the record you need," but that won't help you if you want to use Unlocked/Managed/2nd Gen Managed packages. You need code that stands alone without creating this record. The DML limitation only applies to Apex, and not to standard APIs.