function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdcChi2sfdcChi2 

Test class (dml not allowed on UserTeamMember)

I'm trying to write a test class on the code below. However i can only achieve 66% as i cannot insert the UserTeamMember object with a dml statement.  The 2 lines of code marked  as No Code Coverage are the only lines not covered and mainly because i can't insert the object. would appreciate any help . thanks !!!

trigger SSSUpdate on User (before Update)
{

Map<Id,Id> mapUserTeamIdVsuserId = new Map<Id,Id>();
for(UserTeamMember u :  [SELECT id,UserId,ownerid, User.Name FROM UserTeamMember where TeamMemberRole= 'Sales Support Specialist' AND OwnerId IN:Trigger.New]){
  mapUserTeamIdVsuserId.put(u.OwnerId,U.UserId);     (No  CODE COVERAGE)
}

for(User u1 : Trigger.New){
  if(mapUserTeamIdVsuserId.containsKey(u1.id)){
   u1.SSS__c= mapUserTeamIdVsuserId.get(u1.id);          (NO CODE COVERAGE)
  }
}
}
Best Answer chosen by sfdcChi2
Vinit_KumarVinit_Kumar
Yes that's right.

There are couple of ways of doing it :-

1.) Query on existing data of your org by making (SeeallData=true) in your test class.

2.) Insert a user in test class and add it to Opportunity Team with the Team role which is there in your where filter.

Hope this helps !!

All Answers

Vinit_KumarVinit_Kumar
Yes that's right.

There are couple of ways of doing it :-

1.) Query on existing data of your org by making (SeeallData=true) in your test class.

2.) Insert a user in test class and add it to Opportunity Team with the Team role which is there in your where filter.

Hope this helps !!
This was selected as the best answer
sfdcChi2sfdcChi2
thanks Vinit_Kumar! worked!!!
Rajat Koradiya 5Rajat Koradiya 5
Hi Vinay,

First approach I understood, but can u elaborate second approach little bit more because I am creating an opportunity team member but that is not being retrieved in soql on Userteammember?

Thanks,
Rajat