+ Start a Discussion
Pinky 10Pinky 10 

How can I cover below highlighted code

User-added image





File
Edit
Debug
Test
Workspace
Help
<
>
ProspectingStatusUpdater
TrigToValidateContactRoles
Code Coverage: None
API Version:
Go To
1
trigger TrigToValidateContactRoles on Opportunity (before insert, before update) {
2

3
List<OpportunityContactRole> conRoleList = new List<OpportunityContactRole>();
4

5
Set<Id> ownerIdSet = new Set<Id>();
6

7
for(Opportunity opp : Trigger.new){
8
ownerIdSet.add(opp.ownerId);
9
}
10

11
User loggedInUser = [Select Id, Profile.Name from User where id =: UserInfo.getUserId() limit 1];
12

13
List<User> userList = [Select Id, UserRole.Name, Profile.Name from User where id in: ownerIdSet and UserRole.Name != null];
14

15
if(Trigger.isUpdate)
16
conRoleList = [Select Id, OpportunityId from OpportunityContactRole where OpportunityId in: Trigger.newMap.keySet()];
17

18
for(Opportunity opp : Trigger.new)
19
{
20

21
boolean isVerifyRolesValidation = True;
22

23
if(loggedInUser.Profile.Name.contains('System Administrator') || loggedInUser.Profile.Name.contains('Sales - Executive') || loggedInUser.Profile.Name.contains('Sales Operations - Liz Temp'))
24
{
25
isVerifyRolesValidation = false;
26
}
27
else
28
{
29
for(User u : userList)
30
{
31
if(opp.ownerId == u.Id && u.UserRole.Name.contains('Account Management'))
32
{
33
isVerifyRolesValidation = false;
34
break;
35
}
36
}
37
}
38
if(isVerifyRolesValidation){
39

40
if(opp.Probability >= 50)
41
{
42
if(Trigger.isInsert){
43
opp.addError('Contact Roles must be entered for this Opportunity before the Stage can be changed to Proposal or higher');
44
}
45
if(Trigger.isUpdate)
46
{
47
boolean isValid = false;
48
for(OpportunityContactRole cr : conRoleList){
49
if(opp.Id == cr.OpportunityId){
50
isValid = True;
51
break;
52
}
53
}
54

55
if(!isValid){
56
opp.addError('Contact Roles must be entered for this Opportunity before the Stage can be changed to Proposal or higher');
57
}
58
}
59
}
60
}
61
}
62
}
 


 
rajat Maheshwari 6rajat Maheshwari 6

@Pinky, Please provide me the test class code , which you have written for this trigger, so that I would make change over there and will submit you :)

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com