You need to sign in to do that
Don't have an account?
Need Urgent Help for Test Coverage[Try And Catch]
I got 60 % code coverage but i struck over here can anyone please help me to cover the try and catch blocks
if(Q_AircraftType && Q_Position && Q_Hours && Q_Dateoflastflight && Q_DateoflastSim)
{
System.debug('AAAAAAAAAAAAAAA');
if (InsertCnt==0){
system.debug('In the final if line 116');
Aircraft_Contact__c actype = new Aircraft_Contact__c();
actype.RecordType = [select Id from RecordType where Name = 'Aircraft Type Pilot Layout' and SobjectType = 'Aircraft_Contact__c'];
actype.Candidate__c=[Select ts2__Application__r.ts2__Candidate_Contact__c FROM ts2__Prescreen2__c where ts2__Application__c =:ps.ts2__Application__c Limit 1].ts2__Application__r.ts2__Candidate_Contact__c;
actype.Aircraft_Type__c=[select Id from Aircraft_Type__c where name = :A_AircraftType ].Id;
actype.Position_on_A_C_Type__c=A_Position;
try{
actype.Total_Hours__c= integer.valueof(A_Hours);
}
catch(exception e)
{
ps.addError('Please ensure you enter a numeric number in the Total Hours.');
}
A_DateoflastSim=A_DateoflastSim.mid(3, 2)+'/'+A_DateoflastSim.left(2)+'/'+A_DateoflastSim.right(4);
A_Dateoflastflight=A_Dateoflastflight.mid(3, 2)+'/'+A_Dateoflastflight.left(2)+'/'+A_Dateoflastflight.right(4);
try{
actype.Date_of_Last_SIM__c=date.Parse(A_DateoflastSim); }
catch(exception e)
{
ps.addError('Please ensure that you enter you last SIM in the date format of DD-MM-YYY Ie. 31-01-2013');
}
try{
actype.Date_of_Last_Flight__c=date.Parse(A_Dateoflastflight); }
catch(exception e)
{
ps.addError('Please ensure that you enter you last flight in the date format of DD-MM-YYY Ie. 31-01-2013');
}
insert actype;
InsertCnt=InsertCnt+1;
}
}
Hi,
you can pass null value in A_Hours,A_DateoflastSim and A_DateoflastSim in test class,then it go to the catch block .
And if they have some valid values it runs the try block.
Please let me know if u have any problem on same and if this post helps u please throw KUDOS by click on star at left.
if u dont mine can you please give it in code format..........