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
ursmahiursmahi 

i am unable to cover test coverage for this class please help me

public with sharing class mainreports_class {
list<selectoption> v=new list<selectoption>();
public list<selectoption>getGetvalues() {
v.add(new selectoption('Select','--Select Rport--'));
v.add(new selectoption('FR Performance report based on Month','FR Performance report based on Month'));
v.add(new selectoption('MD Order Report','MD Order Report'));
v.add(new selectoption('Region Performance based on CBF','Region Performance based on CBF'));
v.add(new selectoption('Retailer Performance based on Month','Retailer Performance based on Month'));
return v;
}

public String selectedvalue { get; set; }
public String url{ get; set; }
User usr = [Select id,Alias,lastname,ContactId,Profile.name from User where id=:UserInfo.getUserId() Limit 1];
string prof=usr.Profile.name;


public void rpid() {
if(prof=='CMM East Profile')
{
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=East&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=East&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=East&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=East&isdtp=nv';
}

}else if(prof=='CMM South Profile'){
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=South&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=South&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=South&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=South&isdtp=nv';
}

}else if(prof=='CMM North Profile'){
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=North&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=North&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=North&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=North&isdtp=nv';
}

}
else if(prof=='CMM West Profile')
{
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=West&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=West&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=West&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=West&isdtp=nv';
}

}


}



}

 

my test class:

my test class

@istest(seealldata=true)
public class testmainreports_class
{
public static testmethod void test1()
{



mainreports_class c=new mainreports_class();
c.getGetvalues();

 

c.rpid();

}
}

prakash_sfdcprakash_sfdc
//Make prof as a public property
public String prof{get;set;}
User usr = [Select id,Alias,lastname,ContactId,Profile.name from User where id=:UserInfo.getUserId() Limit 1];
prof=usr.Profile.name;
public static testmethod void test1()
{
mainreports_class c=new mainreports_class();

c.getGetvalues();

c.prof='CMM East Profile';
c.selectedvalue ='FR Performance report based on Month';
c.rpid();
c.selectedvalue =='MD Order Report'
c.rpid();

//Like this do for all. Using so many if conditions is not a good coding standard.

}
ursmahiursmahi

Thank you very much bro given ur valuable information......
and if u don`t mine please tell me which is the best way to write that code.......






















<a href=http://www.computerbild.de/download/SoundFrost-8118785.html >youtube downloader</a>
prakash_sfdcprakash_sfdc
You can extend the code which I have written above, if all conditions are covered it will cross 90%

Let me know if you face any issues.

Please mark it as solution and give Kudos if it helped you.
ursmahiursmahi

Hi, actually utold that Using so many if conditions is not a good coding standard. thats why i am asking there is any another way to write the code in a bestway.

prakash_sfdcprakash_sfdc
what the Ids in url which you are assigning ?
e.g. - 00Oa0000007nvMS
ursmahiursmahi
actually my requirment is i have 4 rports with filters like east,west,south,north.and i have 4 profiles.based on profile i want assingn pages to the user
prakash_sfdcprakash_sfdc

As of now I think this code will do, but if in future you need to add more if conditions then create records in some object with fields like "Report Name" and "URL".

Fetch all the records and store it in a Map<String,Map<String,String>>.

then just one line
url=mapname.get(profilename).(selectedvalue);

Done :)