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
Santosh Shah 4Santosh Shah 4 

Not able to pass test code coverage

I'm, just getting 63% code coverage..not able to incerase c..can any one help me
User-added image
Test class:
@isTest
public class TestOpportunityContactRoleHandler {
    @isTest static void TestBeforeInsertMethod(){
        
        Contact ConRec= new Contact();
        ConRec.FirstName = 'Test';
        ConRec.LastName   = 'Test';
        insert ConRec;
        
        Opportunity opps = new opportunity();
        opps.Name='test';
        opps.StageName='Processing';
        insert opps;
        
        OpportunityContactRole oppRole = new OpportunityContactRole();
        oppRole.Role='ROLE1';
        oppRole.ContactId = ConRec.Id;
        oppRole.OpportunityId = opps.Id;
        insert oppRole;
    }

 
Andrew GAndrew G
Hey there 

In your code, you have 
Set<Id> oppIds = new Set<Id>();
Set<String> roles = new Set<String>();
these are "lists" of things, so your SELECT statement will need to use IN not = (equals). so change the WHERE to 
WHERE OpportunityId IN :oppIds AND Role IN :roles

regards
Andrew​​​​​​​
 
Santosh Shah 4Santosh Shah 4
Still getting same code coverage.didnt increase even doing above change
Andrew GAndrew G
Curious
the code logic reads OK - how are you invoking the class?  before or after trigger?

If you are invoking it in a before trigger, then insert a second OCR record.

Thought being is that if it is a before insert trigger, the OCR will not exist in the database until after the save event occurs.

regards
Andrew