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

Test class concern
Hi,
Am new to sales force test class writing test class for displaying records when contacts have any
cases showing error message how to cover these method in test class
==My method===
public void delete()
{
conrecords=true;
viewpanel=false;
editpanel=false;
id aid=apexpages.currentpage().getparameters().get('conname');
con=[select id,lastname, Accountid, name,phone,email,(select id, CaseNumber from cases) from contact where id=:aid];
if(con.cases.size()>0 )
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Fatal, 'You donot delete this record. It related to cases or customerportal contact');
ApexPages.addMessage(myMsg);
}
}
Bold font code covered but how to cover if condition Any one can solve my issue?
Thanks in Advance.
Hi Varun99,
Please try this test methosd which is given below I have written for you you not tested but I beileve it will run perfectly.And donot forget to create an instance of your class.
If it works for you please mar as solved and give kudos to help other !
--
Thanks
Usman
There few thing you needto take care
first of all try to create all the data with in the test method do not query ant data from the that not a good practice
so Varun99 in place of query a account create a new account with in your test method
& if you test method is in 27th version it might cause some issue so you can use (seealldata = true)
or can decrees the version to 25 or low
Thanks SRK for your suggestion and I agreed with you but we should create Mock record instead of (seealldata = true) to run the Test method this was a temporary solution! And Thank you so much for your suggestion.
--
Usman
hi varun
public static testmethod void test(){
Contact con = new Contact(
//put required field with value
) public static testmethod void test(){
Contact con = new Contact(
//put required field with custom value
)
insert con;
apexpages.currentpage().getparameters().put('conname', con);
//initialize class obj
obj.yourmethod();
}