0

Anyone have a good unit test to apply to this? The JScript on the VF page will open one of a couple pages (force.com or VF) based on the record type being loaded.

public Account acct {get; set;}   
public AccountController(ApexPages.StandardController controller)     
{   
    if(ApexPages.currentPage().getParameters().get('id') !=null)
    {
        acct = [Select id, RecordTypeId, RecordType.Name from Account where id=:ApexPages.currentPage().getParameters().get('id')];
    }        
}
 public PageReference redirectAcctNewPage() {

    if(acct.RecordType.Name.equals('Accounting'))
    {   
        return (new ApexPages.StandardController (new Account(Id=acct.Id))).view();
    }
    else 
    {
        pgrf = new PageReference('/apex/myVisualForcePage');
        pgrf.getParameters().put('id', ApexPages.currentPage().getParameters().get('id'));
        pgrf.setRedirect(true);
        return  pgrf;
    }
}

1 Answer 1

1

I have provided one scenario for Accounting Recordtype to write test cases. Same way you need to prepare other Account record for other recordtype which will navigate to Visualforce page.

//get the recordtype of Account
Id redTypeId = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Accounting').getRecordTypeId();

//create Account
Account acct = new Account(Name='test', RecordTypeId=redTypeId,......);
insert acct;

//create pageReference
PageReference page = Page.MyVFP;
Test.setCurrentPage(page);

//pass parameter to the page
ApexPages.currentPage().getParameters().put('id',acct.Id);

//create an instance of controller.
ApexPages.StandardController standrdcontroller = new ApexPages.StandardController(acct);
AccountController mpr_copy = new AccountController(standrdcontroller);
System.assertEquals(.....);

PageReference pg = mpr_copy.redirectAcctNewPage();
String strUrl = pg.getUrl();
//assert your URL
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .