You need to sign in to do that
Don't have an account?
Need a test code coverage for redirect class...thank you in advance
public with sharing class AccRedirect {
private ApexPages.StandardController controller;
public String retURL {get; set;}
public String rType {get; set;}
public String rTypeName{get;set;}
public AccRedirect(ApexPages.StandardController controller) {
this.controller = controller;
retURL = ApexPages.currentPage().getParameters().get('retURL');
rType = ApexPages.currentPage().getParameters().get('RecordType');
rTypeName = [select named1 from recordtype where id=:rType].named1;
}
public PageReference redirect() {
PageReference returnURL;
IF(rTypeName == 'abc' || rTypeName == 'xyz') {
returnURL = new PageReference('/apex/custPage');
}
ELSE {
returnURL = new PageReference('/001/e');
}
returnURL.getParameters().put('retURL', retURL);
returnURL.getParameters().put('RecordType', rType);
returnURL.getParameters().put('rTypeName', rTypeName);
returnURL.setRedirect(true);
return returnURL;
}
}
This is a standard controller, so you need to provide which is the standard controller
I am giving you an example by considering standard controller is "Opportunity"
Below is the test class sample as per your class code, replace your object with "Opportunity".
Try and let me know it works for you or not.
@isTest
Public class AccRedirectTest{
static testmethod void testaccountredirect(){
account acc = new account();
acc.name = 'test';
insert acc;
ApexPages.StandardController sc= new ApexPages.standardController(acc);
// ApexPages.CurrentPage().getParameters().put('retURL','/apex/testPage');
ApexPages.CurrentPage().getParameters().put('retURL','%2F' +acc.id);
//ApexPages.CurrentPage().getparameters().put('rType','abc');
AccRedirect ar= new AccRedirect(sc);
ar.redirect();
}
}
Updated test code accordingly, still it is giving error and test method is not passing. please correct me if iam wrong any where.
below is the error message
Error Message System.QueryException: List has no rows for assignment to SObject Stack Trace Class.AccountRedirect.<init>: line 22, column 1
Class.AccountRedirectTest.testaccountredirect: line 14, column 1
Use this code to cover all lines of your code.
Let me know if you face any issue.
I think error is coming from class. please show entire code of your class and test class with this line no.
Hi Dhaval,
Thanks for your help, i think i am almost near to completion. Still facing below issue while executing.
---------------------------------------------------------------------------
System.QueryException: List has no rows for assignment to SObject
Stack Trace Class.AccountRedirect.<init>: line 22, column 1
Class.AccountRedirectTest.testAccountred: line 26, column 1
-------------------------------------------------------------------------
@isTest
public class AccredirTest{
public static testmethod void testAccountred()
{
List<RecordType> lstRC = [Select id from recordtype where name ='Customer'];
Account acc = new Account();
acc.name = 'Test';
acc.recordtypeid = lstRc[0].Id;
insert acc;
ApexPages.StandardController controller = new ApexPages.StandardController(acc);
ApexPages.CurrentPage().getParameters().put('retURL','/apex/AcctCustPage?id='+acc.id);
ApexPages.CurrentPage().getParameters().put('rType ',lstRc[0].Id);
ApexPages.CurrentPage().getParameters().put('cancelURL','https://cs7.salesforce.com/001/o');
ApexPages.CurrentPage().getParameters().put('ent','Account');
ApexPages.CurrentPage().getParameters().put('_CONFIRMATIONTOKEN','true');
ApexPages.CurrentPage().getParameters().put('saveNewURL','https://cs7.salesforce.com/001/o');
ApexPages.CurrentPage().getParameters().put('nooverride','1');
ApexPages.CurrentPage().getParameters().put('rTypeName ','Customer');
Accredir clsTest = new Accredir(controller);
clsTest.redirect();
}
}