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

How to write test class for the following class i am getting the error List has no row for assignment .
Here Is my class :
And this is my Test Class
public with Sharing class VisitReportpdf{ Public sic_Visit_Report__c VisitReport{get;set;} Public VisitReportpdf(apexpages.standardcontroller controller){ VisitReport= [SELECT id, Name, CreatedBy.name, Our_shares__c, Market_Share__c, Total_demand__c, Visit_title__c, Visit_Date__c, Account__r.name, Competitors__c, Contact__r.name, Internal_Participants__c, Objective__c, Report_details__c FROM Visit_Report__c where id=:ApexPages.CurrentPage().getparameters().get('id')]; } }
And this is my Test Class
@isTest(SeeAllData=true) public Class TestVisitReportpdf{ public static testmethod void test1(){ Account acc= new Account(); acc.name ='TestAccount'; Insert acc; Contact con = new Contact(); Con.lastName='Test Contact'; Con.Accountid=acc.id; Insert con; Visit_Report__c svr = new Visit_Report__c(); svr.Account__c=acc.id; svr.Competitors__c='test Competitors'; svr.Contact__c=con.id; svr.Visit_Date__c=system.today(); svr.Internal_Participants__c='Test Participents'; svr.Our_shares__c=10; svr.Market_Share__c=90; svr.Total_demand__c=100; svr.Objective__c='Commercial'; svr.Report_details__c='Test Report Details'; svr.Visit_title__c='Test visit Title'; Insert svr; ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(svr); VisitReportpdf VRP= new VisitReportpdf(sc); } }
In your controller class, you are querying the record based on id which is passed on page URL. So in your test class, you should add that URL value. Please put the below line code your test class after record insertion(after line no 26).
ApexPages.currentPage().getParameters().put('id', svr.Id);
Thanks,
Benazir.
All Answers
In your controller class, you are querying the record based on id which is passed on page URL. So in your test class, you should add that URL value. Please put the below line code your test class after record insertion(after line no 26).
ApexPages.currentPage().getParameters().put('id', svr.Id);
Thanks,
Benazir.
In your test class you have to pass the id of Visit_Report__c as in the class you are getting this from URL,
Use this "ApexPages.currentPage().getParameters().put('id', svr.Id);" before calling your class.
Thanks