You need to sign in to do that
Don't have an account?
Getting error in Test class
Hi,
I wrote test class for controller called from visualforce page and i am facing problem in getting the id from the VF page. The below is the controller class wiritten
public class RegMassupdate {
public RegMassupdate () {
}
public RegMassupdate (ApexPages.StandardSetController controller) {
}
public List<Registration__c> queryList= new List<Deal_Registration__c>();
public String RegId{get;set;}
public Set <string> dealSet = new Set<string>();
public string approver{get;set;}
public List<SelectOption> getApproverList(){
List<SelectOption> optionsDealList = new List<SelectOption>();
for(Registration__c dealList:[select Approver_1__c from Registration__c where Id=:RegId]){
queryList.add(dealList);
if(dealList.Level_1_Approver_1__c != null && dealList.Level_1_Approver_1__c != ''){
dealSet.add(dealList.Level_1_Approver_1__c);
}
}
for (String allDealList: dealSet){
if (allDealList!= null){
optionsDealList.add(new SelectOption(allDealList,allDealList));
}
}
return optionsDealList;
}
The test class written is as follows
@isTest(seeAllData = true)
Private class RegMassupdateTest{
static testMethod void testdealMassupdateNew(){
Profile p = [select id, name from Profile limit 1];
system.debug('a1b'+p.Name);
User u = new User(ProfileId = p.id,LastName = 'Test', FirstName = 'Test', Username ='test@salesforce.com', Alias='test', CommunityNickname='test Approve', Email='test@email.com',TimeZoneSidKey='America/Chicago',EmailEncodingKey='ISO-8859-1', LanguageLocaleKey='en_US', LocaleSidKey='en_US',IsActive=false,Email_Address__c='test@email.com',EmployeeNumber='6534866',Legacy_Employee_Ref__c='487547');
Insert u;
Account acc=new Account(Name='Test Account3');
Insert acc;
Opportunity oppty=new Opportunity(Name='Test Oppty',AccountId=acc.Id,StageName='01 ',CloseDate=Date.today());
Insert oppty;
Registration__c Reg=new Registration__c ();
Reg.Name='Test Registration1';
Reg.Status__c='Open';
Reg.Opportunity__c=oppty.Id;
Reg.Customer_Account__c=acc.Id;
Reg.Approver_1__c=u.Id;
insert Reg;
test.startTest();
PageReference pageRef = Page.RegUpdate ;
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id', Reg.id);
ApexPages.StandardSetController newController = new ApexPages.StandardSetcontroller(Reg);
RegMassupdate massupdate1= new RegMassupdate(newController);
massupdate1.getApproverList();
test.stopTest();
}
I am facing problem in getting RegId from VF page. Please can you help me in this.
Thank you in advance.
test.startTest();
PageReference pageRef = Page.RegUpdate ;
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id', Reg.id);
ApexPages.StandardSetController newController = new ApexPages.StandardSetcontroller(Reg);
RegMassupdate massupdate1= new RegMassupdate(newController);
massupdate1.RegId = Reg.Id; // add this and your job is done!
massupdate1.getApproverList();
test.stopTest();
}
All Answers
What's the error?
http://www.salesforcefast.com/2012/10/using-sfdc-messageboards-primer.html
test.startTest();
PageReference pageRef = Page.RegUpdate ;
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id', Reg.id);
ApexPages.StandardSetController newController = new ApexPages.StandardSetcontroller(Reg);
RegMassupdate massupdate1= new RegMassupdate(newController);
massupdate1.RegId = Reg.Id; // add this and your job is done!
massupdate1.getApproverList();
test.stopTest();
}
Thank you for your help. It is working fine now:)