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
NNRNNR 

Urgent Requirement plz help me out

HI All,
please help me out for the bellow method how to write test class.

   public void delWrapper(){
   
        rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));         system.debug('rowNum '+rowNum );         wrappers.remove(rowNum);  // here wrappers is pageblockTable method     
        system.debug('wrappers&&&&&&&&&&'+wrappers);        
        lstacc1 =[Select id,Name from Family__c where id=:dcid];         
         system.debug('lstacc1'+lstacc1 );        
        delete lstacc1;
}
IN test class it showing Error ::Arguments can not be null;
test class
obj.rowNum = Integer.valueOf(apexpages.currentpage().getparameters().put('index','1'));
obj.delWrapper();// calling method from test clss

2.constructor.

  Public deosearchpage(){
   AccountID=apexpages.currentpage().getparameters().get('accId');
  if(AccountID!=null){
try{
     Acc=[select id ,name from account where id=:AccountID];
   }
catche(){

  }
}
}
HOw to write test class for above once also
Best Answer chosen by NNR
Ravikant kediaRavikant kedia
Hi,
     You don't nedd to write obj.rowNum = Integer.valueOf(apexpages.currentpage().getparameters().put('index','1'));  You use just below line before to call your class apexpages.currentpage().getparameters().put('index','1'); your variable rowNum automatically will take a value.

All Answers

Ravikant kediaRavikant kedia
Hi,
     You don't nedd to write obj.rowNum = Integer.valueOf(apexpages.currentpage().getparameters().put('index','1'));  You use just below line before to call your class apexpages.currentpage().getparameters().put('index','1'); your variable rowNum automatically will take a value.
This was selected as the best answer
Mudasir WaniMudasir Wani
Hello,

For first one:
You need to create a wrapper data that is wrappers in your case.Once you create data of that insert it in test class.
Once your data is inserted say you entered 2 records.
Then use this one 
apexpages.currentpage().getparameters().put('index','1');
then you can run the test successfuly.

For Second One:
Create an account 
Account acc = new Account();
acc.Name='test';
Insert acc;
then apexpages.currentpage().getparameters().put('accId',acc.id);
Then you can run your tests.

Let me know if you have any difficulty with sample code.

Please mark this as solution if this solves your problem, So that if anyone has this issue this can help.


 
NNRNNR
Thanks  Ravikant kedia,
I need some for help from you for bellow method.
public pagerefernce Accnext(){
 if(Secondary.Guardian_Name__c!=null &&((Secondary.Guardian_Age__c< 18)||(Secondary.Guardian_Age__c==null))){            AddError('Error: Guardian Age should be greater than equals to 18 ');
           return null;
    }
   else{
              try{ Account.Sex__c='F';Upsert(Account);            if( (Secondary.Relationdhip_with_Secondary_Customer__c=='Brother') || (Secondary.Relationdhip_with_Secondary_Customer__c=='Father')                 || (Secondary.Relationdhip_with_Secondary_Customer__c=='Fathein-law') || (Secondary.Relationdhip_with_Secondary_Customer__c=='Husband')                || (Secondary.Relationdhip_with_Secondary_Customer__c=='Son')){
                   Secondary.Gender__c='M';
           }
               Secondary.Account__c= Account.id;
                upsert(Secondary);
               nextTabValue = 'ContactDetails';               
              // adding primary customer into family member
                wrappers[0].name=Account.name;wrappers[0].Gender__c=Account.Sex__c;wrappers[0].Education__c=Account.Education1__c;                 wrappers[0].Marital_Status__c=Account.Marital_Status__c;                 if(Account.Natureofemployment__c=='Self- Employed' || Account.Natureofemployment__c=='Salaried'){                     wrappers[0].Occupation_Types__c='Employed';                 }                else if(Account.Natureofemployment__c=='Not-Employed' &&((Account.Type_of_Employment__c=='House wife') ||(Account.Type_of_Employment__c=='Others'))){                   wrappers[0].Occupation_Types__c='Not Employed';                }                else{                    wrappers[0].Occupation_Types__c='Student';                }                //=========================================================================               // Adding Secondary customer details into family member             if(Secondary.Relationdhip_with_Secondary_Customer__c!='Group Member' && Secondary.Type_of_Relation__c !='Group Member'){                  wrappers[1].name=Secondary.Name;                  wrappers[1].Gender__c=Secondary.Gender__c;                  wrappers[1].Education__c=Secondary.Educations__c;                  wrappers[1].Marital_Status__c=Secondary.Marital_Statuss__c;                  if(Secondary.Nature_of_Employment__c=='Self-Employed' || Secondary.Nature_of_Employment__c=='salaried'){                         wrappers[1].Occupation_Types__c='Employed';                  }                  else if(Secondary.Nature_of_Employment__c=='Not-Employed' &&((Secondary.Type_of_Employment__c=='House wife') ||(Secondary.Type_of_Employment__c=='Others'))){                      wrappers[1].Occupation_Types__c='Not Employed';                  }                  else{                       wrappers[1].Occupation_Types__c='Student';                  }            }