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
GurunathGurunath 

Test coverage Help

Please help, any one suggest me writing test class for this.........

 

//trigger for creating new A/C type in candidate profile

trigger actypetriger on ts2__Prescreen2__c (before insert) {

Boolean Q_AircraftType=false;
Boolean Q_Position=false;
Boolean Q_Hours=false;
Boolean Q_Dateoflastflight=false;
Boolean Q_DateoflastSim=false;
string A_AircraftType;
string A_Position;
string A_Hours;
string A_Dateoflastflight;
string A_DateoflastSim;
string str_QuestionId;
integer InsertCnt=0;

system.debug('Starting of the trigger');
for(ts2__Prescreen2__c ps: trigger.new){
//List<ts2__Prescreen2__c> Listprescreens = [SELECT Name,ts2__Question_ID__c,ts2__Question_ID__r.Name,ts2__Answer_Txt__c,ts2__Question__c,ts2__Answer__c FROM ts2__Prescreen2__c where ts2__Application__c =:ps.ts2__Application__c];
//for (ts2__Prescreen2__c prescreen : Listprescreens )
//{system.debug('In the first for loop line 16');
//system.debug('prescreen.ts2__Question_ID__r.Name'+ prescreen.ts2__Question_ID__r.Name);
/* if (prescreen.ts2__Question_ID__r.Name == 'Aircraft Type')
{
if(prescreen.ts2__Answer__c!='' || prescreen.ts2__Answer__c != Null )
{
Q_AircraftType=true;
A_AircraftType=prescreen.ts2__Answer__c;
}
}

if (prescreen.ts2__Question_ID__r.Name == 'Position')
{
if(prescreen.ts2__Answer__c!='' || prescreen.ts2__Answer__c != Null)
{
Q_Position=true;
A_Position=prescreen.ts2__Answer__c;
}
}

if (prescreen.ts2__Question_ID__r.Name == 'Hours')
{
if(prescreen.ts2__Answer_Txt__c!='' || prescreen.ts2__Answer_Txt__c != Null)
{
Q_Hours=true;
A_Hours=prescreen.ts2__Answer_Txt__c;
}
}

if (prescreen.ts2__Question_ID__r.Name == 'Date of last flight')
{
if(prescreen.ts2__Answer_Txt__c!='' || prescreen.ts2__Answer_Txt__c != Null)
{
Q_Dateoflastflight=true;
A_Dateoflastflight=prescreen.ts2__Answer_Txt__c;
}
}

if (prescreen.ts2__Question_ID__r.Name == 'Date of last Sim')
{
if(prescreen.ts2__Answer_Txt__c!='' || prescreen.ts2__Answer_Txt__c!= Null)
{
Q_DateoflastSim=true;
A_DateoflastSim=prescreen.ts2__Answer_Txt__c;
}
}
}
if(Q_AircraftType && Q_Position && Q_Hours && Q_Dateoflastflight && Q_DateoflastSim)
{
system.debug('In the first for loop if condition line 60');
}
else
{*/
system.debug('In the else part line 63');
str_QuestionId=[Select name from ts2__Question__c where Id=:ps.ts2__Question_ID__C limit 1].name;
system.debug('str_QuestionId' + str_QuestionId);
if(!Q_AircraftType)
{
if (str_QuestionId == 'Aircraft Type')
{
if(ps.ts2__Answer__c!='' || ps.ts2__Answer__c != Null)
{
Q_AircraftType=true;
A_AircraftType=ps.ts2__Answer__c;
}
}
}
if(!Q_Position)
{
if (str_QuestionId == 'Position')
{
if(ps.ts2__Answer__c!='' || ps.ts2__Answer__c != Null)
{
Q_Position=true;
A_Position=ps.ts2__Answer__c;
}
}
}
if(!Q_Hours)
{
if (str_QuestionId == 'Hours')
{
if(ps.ts2__Answer_Txt__c!='' || ps.ts2__Answer_Txt__c != Null)
{
Q_Hours=true;
A_Hours=ps.ts2__Answer_Txt__c;
}
}
}
if(!Q_Dateoflastflight)
{
if (str_QuestionId == 'Date of last flight')
{
if(ps.ts2__Answer_Txt__c!='' || ps.ts2__Answer_Txt__c != Null)
{
Q_Dateoflastflight=true;
A_Dateoflastflight=ps.ts2__Answer_Txt__c;
}
}
}
if(!Q_DateoflastSim)
{
if (str_QuestionId == 'Date of last Sim')
{
if(ps.ts2__Answer_Txt__c!='' || ps.ts2__Answer_Txt__c != Null)
{
Q_DateoflastSim=true;
A_DateoflastSim=ps.ts2__Answer_Txt__c;
}
}
}

if(Q_AircraftType && Q_Position && Q_Hours && Q_Dateoflastflight && Q_DateoflastSim)
{
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= '003M000000P1sSq';
system.debug('### ps: '+ps);
system.debug('### ps: '+ps.ts2__Application__c);
system.debug('### ps: '+ps.ts2__Application__r.ts2__Candidate_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.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;
actype.Total_Hours__c= integer.valueof(A_Hours);
//actype.Total_Hours__c= Integer.parseInt((A_Hours));

//A_DateoflastSim=A_DateoflastSim.replace( '-' , '/' );
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);
//A_Dateoflastflight=A_Dateoflastflight.replace( '-' , '/' );
actype.Date_of_Last_SIM__c=date.Parse(A_DateoflastSim);
actype.Date_of_Last_Flight__c=date.Parse(A_Dateoflastflight);
insert actype;
InsertCnt=InsertCnt+1;
}
}


// }

//}
}


}

Abhi_TripathiAbhi_Tripathi

Hey Gurunath,

 

Go for this post, and try it yourself, it will definetly hepl you

 

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html