+ Start a Discussion
NNRNNR 

Need Unit Test class for Bellow Method

Hi All,
plz help me out...

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';                  }            }
 


Thanks in Advance....
Nitish VermaNitish Verma
Create Secondary object such that it under goes all if condition and then in your test class call Accnext() method.
NNRNNR
Hi Nitish Verma,
 My test code is
// Secondary instance of secondary object
                  obj.Secondary.Guardian_Name__c='kishore';
                 obj.Secondary.Guardian_Age__c=8;
                 obj.AccNext();
                 obj.Secondary.Guardian_Name__c='kishore';
                 obj.Secondary.Guardian_Age__c=null;
                 obj.AccNext();