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
Varun99Varun99 

Test class

Hi,

public void view()
{
aid=apexpages.currentpage().getparameters().get('conname');
con=[select id,lastname,name,phone,email,Department,Mailingcity,Mailingstreet,Mailingcountry,Mailingpostalcode,accountid from contact where id=:aid];
}

 

How to call view() in test class am calling following way am getting Error

 

System.QueryException: List has no rows for assignment to SObject Stack Trace Class.Contactview.view: line 30, column 1
Class.Contactview.Test: line 115, column 1

 

 

========This is my test method=========

@isTest
Static void Test()
{
account a=new account(name='acc');
insert a;
contact c=new contact();
c.lastname='suresh';
c.firstname='reddy';
c.phone='8899887778';
c.email='test@test.com';
c.Department='sales';
c.Mailingcity='Hyd';
c.Mailingstreet='anand nagar';
c.Mailingcountry='india';
c.Mailingpostalcode='500082';
c.accountid=a.id;
insert c;
if(c.id!=null)
{
apexpages.currentpage().getparameters().put('Id',c.id);
}
Contactview con=new Contactview();
con.getcontactpage();
con.view();
con.getconview();
}

 

 

 

Thanks in Advance

Best Answer chosen by Admin (Salesforce Developers) 
Devendra@SFDCDevendra@SFDC
Hi,

You need to make one change,

apexpages.currentpage().getparameters().put('conname',c.id);

Thanks,
Devendra

All Answers

Devendra@SFDCDevendra@SFDC
Hi,

You need to make one change,

apexpages.currentpage().getparameters().put('conname',c.id);

Thanks,
Devendra
This was selected as the best answer
Varun99Varun99

Hi Devendra,

 

 

It is working, Thanks for your reply.

 

 

 

Thank you