You need to sign in to do that
Don't have an account?

Apex Class: Certain Lines not covered
Hi Experts,
I need some assistance with my apex class. Certain lines are not covered. I am only getting 72% on code coverage:
APEX CLASS:
These lines are not covered:
I need some assistance with my apex class. Certain lines are not covered. I am only getting 72% on code coverage:
APEX CLASS:
public class LeadViewRestriction { public LeadViewRestriction(ApexPages.StandardController controller) { this.controller = controller; } public PageReference getRedir() { Lead l = [Select id, OwnerId From Lead Where Id =: ApexPages.currentPage().getParameters().get('id')]; User u = [Select Id, Profile.Name from User where Id =: UserInfo.getUserId()]; PageReference newPage; if (u.Profile.Name == 'VL - Sales Agent' && l.OwnerId != u.Id) { newPage = Page.LeadBasicView; } else { return null; } newPage.getParameters().put('id', l.Id); return newPage.setRedirect(true); } private final ApexPages.StandardController controller; }
@isTest private class TestLeadViewRestriction { @isTest static void testsLeadView() { Lead l = new Lead(); l.Company = 'Test'; l.LastName = 'Doe'; l.Lead_Status_NEW__c = 'New'; insert l; Test.startTest(); PageReference newPage = Page.LeadBasicView; Test.setCurrentPage(newPage); Test.setCurrentPageReference(newPage); newPage.getParameters().put('id',l.id); ApexPages.StandardController sc = new ApexPages.standardController(l); LeadViewRestriction controller = new LeadViewRestriction (sc); controller.getRedir(); } }
These lines are not covered:
Line 14 of Apex Class: newPage = Page.LeadBasicView; Line 20: newPage.getParameters().put('id', l.Id); Line 21: return newPage.setRedirect(true);
Please try below code