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 

Need Urgent Help for Writing Test class

Please any one help me writing the test class for this ....helped one would be greately appriciated.

 

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

trigger actypetriger on ts2__Prescreen2__c (after 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){

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




}


}

 

aarya1aarya1

@isTest
private class Test_actypetriger {
 
  static testMethod void testSave() {

 

 ts2__Prescreen2__c    ts = new  ts2__Prescreen2__c ();

 

Test.startTest();

 

 

insert ts;

 

Aircraft_Contact__c actype = new Aircraft_Contact__c();

actype.Candidate__c='  text';

actype.Total_Hours__c=20;

actype . RecordType Id='23weeww223132';

actype.Date_of_Last_Flight__c=false;

 

 

 

insert;

 

 

 

Test.stopTest();

}

}

 

 

 

 

 

 

 

 

}

 

 

 

 

}

 

Abhi_TripathiAbhi_Tripathi

Hey,

 

Go for this post it will surely help you

 

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

 

Mark this solution correct with kudos (star) if it helps you