• Avinash Ravisankar 13
  • NEWBIE
  • 0 Points
  • Member since 2017
  • 4i Apps

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 1
    Replies
Hi,

I have a main class with the following lines inside of it. I'm unable to cover these if blocks in my test class. Please help out.
 
if(con.FirstName == null)
       {inputTextErrorMessage='Please enter "First Name"';
       }
       if(con.LastName__c == null)
       {inputTextErrorMessage2='Please enter "Last Name"';
       }
       if(con.Country_Code__c == null || con.ContactPhone__c == null)
       
       {inputTextErrorMessage4='Please choose "Country Code" & enter "Mobile Number"';
       }
       if(con.Email == null)
       {inputTextErrorMessage5='Please enter "Email"';
       }
       if(con.Nationality__c == 'Nationality*')
       {inputTextErrorMessage6='Please choose "Nationality"';
       }
       if(con.Preferred_Time_to_Call__c == 'Preferred time to Call* (GMT +4)')
       {inputTextErrorMessage7='Please choose "Preferred time to Call"';
       return null;}
        
        
       
    
con.LastName = con.LastName__c  ;     
string conname = con.FirstName+' '+con.LastName__c;
system.debug('conname====>'+conname );
integer flag =1;
list<contact> conlist = [select name,email from contact ];
for(contact c:conlist){
if(c.name == conname && c.email == con.email){
pba__Request__c r = new pba__Request__c();
r.pba__Contact__c = c.id;
r.status__c = 'Pending';

try{
    list<pba__Request__c> relist = [select id,pba__Contact__c,status__c, createddate from pba__Request__c];
         for(pba__Request__c req:relist)
         {
                if(r.pba__Contact__c == req.pba__Contact__c)
                {
                   if((req.status__c == 'Active' || req.status__c == 'Pending')&& (req.createddate.date().daysbetween(System.today()))<7)
                   {
                          pagereference pg = new pagereference('https://c.cs86.visual.force.com/apex/OmniyatErrMsg');
                          return pg;
                          return null;
       
       }
    
    }
    }
    }
    catch(DMLException e) 
        {
          return null;
        }  
insert r;
flag++;
}
}
system.debug('flag==='+flag);
if(flag==1)
{

insert con;
pba__Request__c r = new pba__Request__c();
r.pba__Contact__c = con.id;
r.status__c = 'Active';
insert r;

}


/*ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha');
            ApexPages.addMessage(errorMsg);
            return null;*/

pagereference pg = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou');
return pg;
       
        }

Thanks,
Avinash