+ 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:
public class TestOpportunityContactRoleHandler {
    @isTest static void TestBeforeInsertMethod(){
        Contact ConRec= new Contact();
        ConRec.FirstName = 'Test';
        ConRec.LastName   = 'Test';
        insert ConRec;
        Opportunity opps = new opportunity();
        insert opps;
        OpportunityContactRole oppRole = new OpportunityContactRole();
        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

Santosh Shah 4Santosh Shah 4
Still getting same code coverage.didnt increase even doing above change
Andrew GAndrew G
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.