You need to sign in to do that
Don't have an account?
Rahul Sharma 390
to call a pageref method into test class
my class ------>
public without sharing class AllBeatMaps {
public list<Beat_Map__c> bmapList {get;set;}
public list<User> salesRepList {get;set;}
public String pageTitle {get;set;}
public String querytype {get;set;}
public AllBeatMaps(){
pageTitle='SELECT BEAT MAP';
String salesRep = 'Sales Rep';
querytype = apexpages.currentPage().getParameters().get('type');
String query1 = 'SELECT Id,Name,Beat_Definition__c FROM Beat_Map__c';
String query2 = 'SELECT Id,Name,Userrole.Name FROM User WHERE UserRole.Name=';
if(querytype!=null && querytype.trim().length()>0){
if(querytype=='beatmap'){
bmapList = Database.query(query1);
}
if(querytype=='salesrep'){
pageTitle = 'SELECT SALES REP';
query2+='\''+salesRep+'\'';
salesRepList=Database.query(query2);
}
}
}
}
Test Class ---------->
@isTest
public class AllBeatMapsTest {
public static testmethod void allbeatmptest(){
profile SalesRep = [Select Id FROM Profile Where Name= 'Sales Representative'];
userRole urp = new UserRole(Name = 'Sales Rep');
insert urp;
User ur = new User(UserRoleid=urp.Id,ProfileId = SalesRep.Id,Alias = 'hfsre',Country='India',Email='defo1@urturiurain.com',EmailEncodingKey='UTF-8', LastName='oiuriuterh', LanguageLocaleKey='en_US',LocaleSidKey='en_US',TimeZoneSidKey='America/Los_Angeles', UserName='wdjhfgb@b.com');
insert ur;
system.runAs(ur){
list<User> usa = new list<User>();
usa.add(ur);
Beat_Map__c bm = new Beat_Map__c();
bm.Beat_Definition__c = 'Gurugram Sector 14,17,21,23';
insert bm;
list<Beat_Map__c> bmc = new list<Beat_Map__c>();
bmc.add(bm);
PageReference pageRef = Page.AllBeatMaps;
Beat_Map__c bcc = new Beat_Map__c();
bcc.Beat_Definition__c = 'Gurugram Sector 45,17,21,23';
insert bcc;
Test.setCurrentPage(pageRef);
pageRef.getParameters().put('id',bcc.id);
AllBeatMaps obh = new AllBeatMaps();
}
}
}
public without sharing class AllBeatMaps {
public list<Beat_Map__c> bmapList {get;set;}
public list<User> salesRepList {get;set;}
public String pageTitle {get;set;}
public String querytype {get;set;}
public AllBeatMaps(){
pageTitle='SELECT BEAT MAP';
String salesRep = 'Sales Rep';
querytype = apexpages.currentPage().getParameters().get('type');
String query1 = 'SELECT Id,Name,Beat_Definition__c FROM Beat_Map__c';
String query2 = 'SELECT Id,Name,Userrole.Name FROM User WHERE UserRole.Name=';
if(querytype!=null && querytype.trim().length()>0){
if(querytype=='beatmap'){
bmapList = Database.query(query1);
}
if(querytype=='salesrep'){
pageTitle = 'SELECT SALES REP';
query2+='\''+salesRep+'\'';
salesRepList=Database.query(query2);
}
}
}
}
Test Class ---------->
@isTest
public class AllBeatMapsTest {
public static testmethod void allbeatmptest(){
profile SalesRep = [Select Id FROM Profile Where Name= 'Sales Representative'];
userRole urp = new UserRole(Name = 'Sales Rep');
insert urp;
User ur = new User(UserRoleid=urp.Id,ProfileId = SalesRep.Id,Alias = 'hfsre',Country='India',Email='defo1@urturiurain.com',EmailEncodingKey='UTF-8', LastName='oiuriuterh', LanguageLocaleKey='en_US',LocaleSidKey='en_US',TimeZoneSidKey='America/Los_Angeles', UserName='wdjhfgb@b.com');
insert ur;
system.runAs(ur){
list<User> usa = new list<User>();
usa.add(ur);
Beat_Map__c bm = new Beat_Map__c();
bm.Beat_Definition__c = 'Gurugram Sector 14,17,21,23';
insert bm;
list<Beat_Map__c> bmc = new list<Beat_Map__c>();
bmc.add(bm);
PageReference pageRef = Page.AllBeatMaps;
Beat_Map__c bcc = new Beat_Map__c();
bcc.Beat_Definition__c = 'Gurugram Sector 45,17,21,23';
insert bcc;
Test.setCurrentPage(pageRef);
pageRef.getParameters().put('id',bcc.id);
AllBeatMaps obh = new AllBeatMaps();
}
}
}
Try this,
Thanks !!!
If it helps you, please mark is as best answer, so it will be helpful for other developers.
All Answers
Try this,
Thanks !!!
If it helps you, please mark is as best answer, so it will be helpful for other developers.
Gokula Krishnan