• Gurunath
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 8
    Replies

Hi any one please help me to cover these lines.......


public with sharing class ExpenseListEditController
{

public List<ExpenseKeyWrapper> wrappers {get; set;}

public Integer addItemCount {get; set;}


public Integer keyToDelete {get; set;}

public Integer mainKey {get; set;}

public Expense_Sheet__c expSheet {get; set;}

public string idParam;

private List<Expense__c> toDelete=new List<Expense__c>();

public ExpenseListEditController()
{
mainKey=1;
addItemCount=3;


idParam = apexpages.currentpage().getparameters().get('Id');

buildexpensesheet();
}

Public void buildexpensesheet() {
wrappers=new List<ExpenseKeyWrapper>();
expSheet = [Select Name, Employee__c, Month__c, Year__c , total__c FROM Expense_Sheet__c WHERE id =:idParam];
List<Expense__c> expenses=[select id, Date__c,Receipt_Number__c, Description__c, Type__c, Amount__c, Vat_Code__c, Expense_Sheet__c from Expense__c WHERE Expense_Sheet__c = :idParam LIMIT 1000];
for (Expense__c exps : expenses)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, exps));
}
}


public PageReference addItems()
{
if ( (addItemCount>0) && (addItemCount<10) )
{
for (Integer idx=0; idx<addItemCount; idx++)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, new Expense__c()));
}
}

return null;
}


public PageReference removeItem()
{
Integer idx=0;
Boolean found=false;
for (ExpenseKeyWrapper wrap : wrappers)
{
if (wrap.key==keyToDelete)
{
found=true;
if (null!=wrap.expense.id)
{
toDelete.add(wrap.expense);
}
break;
}
else
{
idx++;
}
}

if (found)
{
wrappers.remove(idx);
}

return null;
}


public PageReference save()
{
PageReference result=null;
Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();


for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
if (String.IsBlank(wrapper.expense.Receipt_Number__c))
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;


result=new PageReference('/' + idParam);
}

return result;
}

public PageReference updatetotal()
{

Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();


for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;

}

buildexpensesheet();

return Null;
}
}

 

Test Class For this

==========================

 

@isTest(seeAllData = true)

Public class TestExpenseListEditController{

public Integer idx = 0;
public Integer addItemCount = 10;
public Integer keyToDelete = 21;
public Integer mainKey = 12;
public string idParam = 'First String';
Public boolean found = False;
//Public boolean found = true;
Public PageReference result = null;
Public Boolean error = false;


public static testMethod void TestExpenseListEditController1(){

Integer inKey = 52;



SFDC_Employee__c se = new SFDC_Employee__c();
se.Name = 'Indian';
Insert se;

Expense_Sheet__c es = new Expense_Sheet__c();
es.Approved__c = true;
es.Month__c = 'January';
es.Year__c = '2013';
es.Employee__c = se.Id;

Insert es;

Expense_Sheet__c es1 = new Expense_Sheet__c();
es1.Approved__c = true;
es1.Month__c = 'January';
es1.Year__c = '2013';
es1.Employee__c = se.Id;

Insert es1;

Expense_Sheet__c es2 = new Expense_Sheet__c();
es2.Approved__c = true;
es2.Month__c = 'January';
es2.Year__c = '2013';
es2.Employee__c = se.Id;

Insert es2;

Apexpages.currentpage().getparameters().put('Id',es.id);

Expense__c ep = new Expense__c();
ep.Description__c = 'First test';
ep.Expense_Sheet__c = es.Id;
ep.Receipt_Number__c = '1234567';
ep.Type__c = 'Equipment';
ep.Vat_Code__c = 'First test';

Insert ep;

Expense__c ep1 = new Expense__c();
ep1.Description__c = 'First test';
ep1.Expense_Sheet__c = es.Id;
ep1.Receipt_Number__c = '1234567';
ep1.Type__c = 'Equipment';
ep1.Vat_Code__c = 'First test';

Insert ep1;


Expense__c ep2 = new Expense__c();
ep2.Description__c = 'First test';
ep2.Expense_Sheet__c = es.Id;
ep2.Receipt_Number__c = '1234567';
ep2.Type__c = 'Equipment';
ep2.Vat_Code__c = 'First test';

Insert ep2;

Upsert ep2;
Delete ep2;


ExpenseKeyWrapper eWrapper = new ExpenseKeyWrapper(inKey,ep);
// eWrapper =


System.assertEquals(inKey, eWrapper.key);
//System.assertEquals(ep1, eWrapper.ep1);



ExpenseListEditController ELEC = new ExpenseListEditController();

ELEC.addItems();
ELEC.removeItem();
ELEC.Save();
ELEC.updatetotal();

}


}

Hi any one please help me to cover these lines.......


public with sharing class ExpenseListEditController
{

public List<ExpenseKeyWrapper> wrappers {get; set;}

public Integer addItemCount {get; set;}


public Integer keyToDelete {get; set;}

public Integer mainKey {get; set;}

public Expense_Sheet__c expSheet {get; set;}

public string idParam;

private List<Expense__c> toDelete=new List<Expense__c>();

public ExpenseListEditController()
{
mainKey=1;
addItemCount=3;


idParam = apexpages.currentpage().getparameters().get('Id');

buildexpensesheet();
}

Public void buildexpensesheet() {
wrappers=new List<ExpenseKeyWrapper>();
expSheet = [Select Name, Employee__c, Month__c, Year__c , total__c FROM Expense_Sheet__c WHERE id =:idParam];
List<Expense__c> expenses=[select id, Date__c,Receipt_Number__c, Description__c, Type__c, Amount__c, Vat_Code__c, Expense_Sheet__c from Expense__c WHERE Expense_Sheet__c = :idParam LIMIT 1000];
for (Expense__c exps : expenses)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, exps));
}
}


public PageReference addItems()
{
if ( (addItemCount>0) && (addItemCount<10) )
{
for (Integer idx=0; idx<addItemCount; idx++)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, new Expense__c()));
}
}

return null;
}


public PageReference removeItem()
{
Integer idx=0;
Boolean found=false;
for (ExpenseKeyWrapper wrap : wrappers)
{
if (wrap.key==keyToDelete)
{
found=true;
if (null!=wrap.expense.id)
{
toDelete.add(wrap.expense);
}
break;
}
else
{
idx++;
}
}

if (found)
{
wrappers.remove(idx);
}

return null;
}


public PageReference save()
{
PageReference result=null;
Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();


for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
if (String.IsBlank(wrapper.expense.Receipt_Number__c))
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;


result=new PageReference('/' + idParam);
}

return result;
}

public PageReference updatetotal()
{

Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();


for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;

}

buildexpensesheet();

return Null;
}
}

Hi i have two objects ,can any one help me to crack the relationship fields

Budget_Building__c(parent)

Budget_Line_Item__c(child)

relationbship between is Look-up

 

in child i have one field like August_Budget_Local_Amount__c how can i retrieve this field from parent....

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

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




}


}

 

I wrote the test class  and i am getting 70% code coverage  however my controller class has the wrapper class ,here i was struck. can any one help me to write the testcode for wrapperclass.

 

Here Is My controller Class

========================

/****************************************************************************
* Custom controller for the managing a list of expenses for an expense sheet
* Manages a list of expense records, holding insert/delete
* information in memory until the user chooses to save the changes.
***************************************************************************/
public with sharing class ExpenseListEditController
{
// wrapper classes for the contacts being managed
public List<ExpenseKeyWrapper> wrappers {get; set;}

// when a user chooses to add items, the number of
// items to add will be present in this property
public Integer addItemCount {get; set;}

// when a user deletes a record, the record key will
// be present in this property
public Integer keyToDelete {get; set;}

// the unique record key master value
public Integer mainKey {get; set;}

public Expense_Sheet__c expSheet {get; set;}

// string to hold Expense sheet Is
public string idParam;

// the records to delete when the user saves their work
private List<Expense__c> toDelete=new List<Expense__c>();

// constructor
public ExpenseListEditController()
{
mainKey=1;
addItemCount=3;


idParam = apexpages.currentpage().getparameters().get('Id');

buildexpensesheet();
}

Private void buildexpensesheet() {
wrappers=new List<ExpenseKeyWrapper>();
expSheet = [Select Name, Employee__c, Month__c, Year__c , total__c FROM Expense_Sheet__c WHERE id =:idParam];
// get the current expenses from the database for the current expense sheets
List<Expense__c> expenses=[select id, Date__c,Receipt_Number__c, Description__c, Type__c, Amount__c, Vat_Code__c, Expense_Sheet__c from Expense__c WHERE Expense_Sheet__c = :idParam LIMIT 1000];
for (Expense__c exps : expenses)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, exps));
}
}

// add a number of items to the list
public PageReference addItems()
{
if ( (addItemCount>0) && (addItemCount<10) )
{
for (Integer idx=0; idx<addItemCount; idx++)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, new Expense__c()));
}
}

return null;
}

// remove (delete) an item from the list
public PageReference removeItem()
{
Integer idx=0;
Boolean found=false;
for (ExpenseKeyWrapper wrap : wrappers)
{
if (wrap.key==keyToDelete)
{
found=true;
if (null!=wrap.expense.id)
{
toDelete.add(wrap.expense);
}
break;
}
else
{
idx++;
}
}

if (found)
{
wrappers.remove(idx);
}

return null;
}

// save the users work
public PageReference save()
{
PageReference result=null;
Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();

// make sure that if any data has been entered, the
// last name is present as this is required
for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
if (String.IsBlank(wrapper.expense.Receipt_Number__c))
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;

// return the user to the contacts tab
result=new PageReference('/' + idParam);
}

return result;
}

public PageReference updatetotal()
{

Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();

// make sure that if any data has been entered, the
// last name is present as this is required
for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;

}

buildexpensesheet();

return Null;
}
}

Test Class for this (Getting 70% code coverage) suggest any one writing test class for wrapper class

================================================================================

 

@isTest(seeAllData = true)

Public class TestExpenseListEditController{

public Integer idx = 0;
public Integer addItemCount = 10;
public Integer keyToDelete = 21;
public Integer mainKey = 12;
public string idParam = 'First String';
Public boolean found = true;
//Public boolean found = true;
Public PageReference result = null;
Public Boolean error = false;


public static testMethod void TestExpenseListEditController(){

Integer inKey = 52;



SFDC_Employee__c se = new SFDC_Employee__c();
se.Name = 'Indian';
Insert se;

Expense_Sheet__c es = new Expense_Sheet__c();
es.Approved__c = true;
es.Month__c = 'January';
es.Year__c = '2013';
es.Employee__c = se.Id;

Insert es;

Expense_Sheet__c es1 = new Expense_Sheet__c();
es1.Approved__c = true;
es1.Month__c = 'January';
es1.Year__c = '2013';
es1.Employee__c = se.Id;

Insert es1;

Expense_Sheet__c es2 = new Expense_Sheet__c();
es2.Approved__c = true;
es2.Month__c = 'January';
es2.Year__c = '2013';
es2.Employee__c = se.Id;

Insert es2;

Apexpages.currentpage().getparameters().put('Id',es.id);

Expense__c ep = new Expense__c();
ep.Description__c = 'First test';
ep.Expense_Sheet__c = es.Id;
ep.Receipt_Number__c = '1234567';
ep.Type__c = 'Equipment';
ep.Vat_Code__c = 'First test';

Insert ep;

Expense__c ep1 = new Expense__c();
ep1.Description__c = 'First test';
ep1.Expense_Sheet__c = es.Id;
ep1.Receipt_Number__c = '1234567';
ep1.Type__c = 'Equipment';
ep1.Vat_Code__c = 'First test';

Insert ep1;


Expense__c ep2 = new Expense__c();
ep2.Description__c = 'First test';
ep2.Expense_Sheet__c = es.Id;
ep2.Receipt_Number__c = '1234567';
ep2.Type__c = 'Equipment';
ep2.Vat_Code__c = 'First test';

Insert ep2;

Upsert ep2;
Delete ep2;


ExpenseKeyWrapper eWrapper = new ExpenseKeyWrapper(inKey,ep);

System.assertEquals(inKey, eWrapper.key);
//System.assertEquals(ep1, eWrapper.ep1);



ExpenseListEditController ELEC = new ExpenseListEditController();

ELEC.addItems();
ELEC.removeItem();
ELEC.Save();
ELEC.updatetotal();




}

}

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


// }

//}
}


}

Please help me anyone writing the test class for this .......

 

while at the time of  writing test class i am facing the problem like List has no rows for assignment to SObject

 

public with sharing class ExpenseListEditController
{
// wrapper classes for the contacts being managed
public List<ExpenseKeyWrapper> wrappers {get; set;}

// when a user chooses to add items, the number of
// items to add will be present in this property
public Integer addItemCount {get; set;}

// when a user deletes a record, the record key will
// be present in this property
public Integer keyToDelete {get; set;}

// the unique record key master value
public Integer mainKey {get; set;}

public Expense_Sheet__c expSheet {get; set;}

// string to hold Expense sheet Is
public string idParam;

// the records to delete when the user saves their work
private List<Expense__c> toDelete=new List<Expense__c>();

// constructor
public ExpenseListEditController()
{
mainKey=1;
addItemCount=3;


idParam = apexpages.currentpage().getparameters().get('Id');

buildexpensesheet();
}

public void buildexpensesheet() {
wrappers=new List<ExpenseKeyWrapper>();
expSheet = [Select Name, Employee__c, Month__c, Year__c , total__c FROM Expense_Sheet__c WHERE id =:idParam];
// get the current expenses from the database for the current expense sheets
List<Expense__c> expenses=[select id, Date__c,Receipt_Number__c, Description__c, Type__c, Amount__c, Vat_Code__c, Expense_Sheet__c from Expense__c WHERE Expense_Sheet__c = :idParam LIMIT 1000];
for (Expense__c exps : expenses)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, exps));
}
}

// add a number of items to the list
public PageReference addItems()
{
if ( (addItemCount>0) && (addItemCount<10) )
{
for (Integer idx=0; idx<addItemCount; idx++)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, new Expense__c()));
}
}

return null;
}

// remove (delete) an item from the list
public PageReference removeItem()
{
Integer idx=0;
Boolean found=false;
for (ExpenseKeyWrapper wrap : wrappers)
{
if (wrap.key==keyToDelete)
{
found=true;
if (null!=wrap.expense.id)
{
toDelete.add(wrap.expense);
}
break;
}
else
{
idx++;
}
}

if (found)
{
wrappers.remove(idx);
}

return null;
}

// save the users work
public PageReference save()
{
PageReference result=null;
Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();

// make sure that if any data has been entered, the
// last name is present as this is required
for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
if (String.IsBlank(wrapper.expense.Receipt_Number__c))
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;

// return the user to the contacts tab
result=new PageReference('/' + idParam);
}

return result;
}

public PageReference updatetotal()
{

Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();

// make sure that if any data has been entered, the
// last name is present as this is required
for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;

}

buildexpensesheet();

return Null;
}
}

Any one help me writing test class for this........

 

public with sharing class ExpenseKeyWrapper
{
public Integer key {get; set;}
public Expense__c expense {get; set;}

public ExpenseKeyWrapper(){}

public ExpenseKeyWrapper(Integer inKey, Expense__c inExpense)
{
key=inKey;
expense=inExpense;
}
}

Please anyone suggest me solution for this issue (Except renderedAs)

I have two fields one date_of _last_flight__c and date_of_last_sim__c in Aircraft_Contact__c object, these two fileds should be in date format like dd-mm-yyyy other wise i have to show the error like date should be in date format.........any one suggest me writing the validation trigger for this 

Voucher is parent object and treasure_chest_application__c is my child object ,the issue is i could not able to cover the code for this in test class.......can please help to me  in writing test class for this............

 

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null ){

if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA.Date_of_the_Event__c.year())){

RelatedVoucher.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher ){
TotalRaffles = 0 ;
TotalEvents = 0 ;
NumberEventsBenefiting = 0;

for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){


// NumberEventsBenefiting += Integer.valueOf(TCA1.get('expr0'));
NumberEventsBenefiting++;
TotalRaffles += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
system.debug('&&&&&&&&&&&&&&&&&&&&&&&&&&&'+ TotalRaffles);
}
}
}
}

Controller Class Is:

 

public class VoucherContactReport{

public String Voucherid {get; set;}
public Integer NumberEventsBenefiting{get; set;}
public Integer NumberEventsBenefiting3{get; set;}
public Integer NumberEventsBenefiting6{get; set;}
public Integer NumberEventsBenefiting12{get; set;}

public Integer NumberEventsBenefitingAllTime{get; set;}
public Integer CountOfEB{get; set;}
Public String CountOfEB1{get;set;}

public static string TotalCount1{get; set;}
public static string TotalCountUsed1{get; set;}



public Integer TotalRaffles{get; set;}
public Integer TotalRaffles3{get; set;}
public Integer TotalRaffles6{get; set;}
public Integer TotalRaffles12{get; set;}
public Integer TotalRafflesAllTime{get; set;}
public Integer LegacyRaffles{get; set;}

public string TotalOfLegacyRaffles{get;set;}
public static string TotalRafflesAllTime1{get; set;}
public static string LegacyRaffles1{get; set;}

public Integer TotalEvents{get; set;}
public Integer TotalEvents3{get; set;}
public Integer TotalEvents6{get; set;}
public Integer TotalEvents12{get; set;}

public Integer TotalEventsAllTime{get; set;}
public Integer LegacyEvent{get; set;}

public string TotalOfLegacyEvent{get;set;}
public static string TotalEventsAllTime1{get; set;}
public static string LegacyEvent1{get; set;}

public List<Voucher__c> RelatedVoucher;
public List<Voucher__c> RelatedVoucher3;
public List<Voucher__c> RelatedVoucher6;
public List<Voucher__c> RelatedVoucher12;
public List<Voucher__c> RelatedVoucherAllTime;
public List<Treasure_Chest_Application__c> RelatedTreasureChestApplications{get; set;}




public VoucherContactReport(){


}


public List<Voucher__c> getRelatedVoucher() {

NumberEventsBenefiting = 0;
TotalRaffles = 0;
TotalEvents = 0;
RelatedVoucher = new List<Voucher__c>();
RelatedTreasureChestApplications = new List<Treasure_Chest_Application__c>();
// this.Voucherid = 'a1Ac0000000VaCi';
if(Voucherid != null && Voucherid!= ''){


//Added for Count of the Event Benifiting



for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null ){

if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA.Date_of_the_Event__c.year())){

RelatedVoucher.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher ){
TotalRaffles = 0 ;
TotalEvents = 0 ;
NumberEventsBenefiting = 0;

for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){


// NumberEventsBenefiting += Integer.valueOf(TCA1.get('expr0'));
NumberEventsBenefiting++;
TotalRaffles += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
system.debug('&&&&&&&&&&&&&&&&&&&&&&&&&&&'+ TotalRaffles);
}
}
}
}
}
return RelatedVoucher;
}




public List<Voucher__c> getRelatedVoucher3() {

NumberEventsBenefiting3 = 0;
TotalRaffles3 = 0;
TotalEvents3 = 0;
RelatedVoucher3 = new List<Voucher__c>();
system.debug('*******************************'+ RelatedVoucher3);


if(Voucherid != null && Voucherid!= ''){


for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){


if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 3) && (date.today().year() == TCA.Date_of_the_Event__c.year())){
RelatedVoucher3.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher3 ){
TotalRaffles3 = 0 ;
TotalEvents3 = 0 ;
NumberEventsBenefiting3 = 0;
for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){

if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null){
if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 3) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){

// NumberEventsBenefiting3 = Integer.valueOf(CalVouchers.Number_of_Events_Benefiting__c);
NumberEventsBenefiting3 ++;
TotalRaffles3 += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents3 += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
}

}
}
}
}

return RelatedVoucher3;

}

 


public List<Voucher__c> getRelatedVoucher6() {

NumberEventsBenefiting6 = 0;
TotalRaffles6 = 0;
TotalEvents6 = 0;
RelatedVoucher6 = new List<Voucher__c>();

if(Voucherid != null && Voucherid!= ''){

for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r)
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){


if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 6) && (date.today().year() == TCA.Date_of_the_Event__c.year())){
RelatedVoucher6.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher6 ){
TotalRaffles6 = 0;
TotalEvents6 = 0;
NumberEventsBenefiting6 = 0;

for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 6) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){

// NumberEventsBenefiting6 = Integer.valueOf(CalVouchers.Number_of_Events_Benefiting__c);
NumberEventsBenefiting6++;
TotalRaffles6 += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents6 += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
}
}
}
}
}
return RelatedVoucher6;
}

 

public List<Voucher__c> getRelatedVoucher12() {

NumberEventsBenefiting12 = 0;
TotalRaffles12 = 0;
TotalEvents12 = 0;
RelatedVoucher12 = new List<Voucher__c>();

if(Voucherid != null && Voucherid!= ''){

for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, Legacy_Amount_Raised_for_Events__c,(select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){



if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 12) && (date.today().year() == TCA.Date_of_the_Event__c.year())){
RelatedVoucher12.add(queryvouchers);
}

}
}
}
for(Voucher__c CalVouchers : RelatedVoucher12 ){
TotalRaffles12 = 0;
TotalEvents12 = 0;
NumberEventsBenefiting12 = 0;


for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 12) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){
// NumberEventsBenefiting12 = Integer.valueOf(CalVouchers.Number_of_Events_Benefiting__c);
NumberEventsBenefiting12++;
TotalRaffles12 += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents12 += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
}
}
}
}
}
return RelatedVoucher12;
}

 


public List<Voucher__c> getRelatedVoucherAllTime() {

NumberEventsBenefitingAllTime = 0;
TotalRafflesAllTime = 0;
TotalEventsAllTime = 0;

RelatedVoucherAllTime = new List<Voucher__c>();

if(Voucherid != null && Voucherid!= ''){
for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate,Legacy_Amount_Raised_for_Vouchers__c,Legacy_Amount_Raised_for_Events__c,Legacy_Used__c, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){



if( (TCA.Date_of_the_Event__c <= date.today()) && (date.today().year() >= TCA.Date_of_the_Event__c.year())) {
RelatedVoucherAllTime.add(queryvouchers);
}

}
}
// RelatedVoucherAllTime.add(queryvouchers);
}
for(Voucher__c CalVouchers : RelatedVoucherAllTime ){

TotalRafflesAllTime = 0;
TotalEventsAllTime = 0;
NumberEventsBenefitingAllTime = 0;


for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if (TCA1.Date_of_the_Event__c <= date.today()) {

NumberEventsBenefitingAllTime++;

integer Count1 = NumberEventsBenefitingAllTime;

CountOfEB1 = String.ValueOf(Count1);
CountOfEB = Integer.ValueOf(CalVouchers.Legacy_Used__c );
TotalCount1 = String.ValueOf(CountOfEB);
TotalCountUsed1 = CountOfEB1+' '+'('+'+'+TotalCount1+')';


TotalRafflesAllTime += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c) ;
TotalRafflesAllTime1 = String.valueOf(TotalRafflesAllTime );


LegacyRaffles = Integer.ValueOf(CalVouchers.Legacy_Amount_Raised_for_Vouchers__c );
LegacyRaffles1 = String.valueOf( LegacyRaffles);
TotalOfLegacyRaffles = TotalRafflesAllTime1+' '+'('+'+'+LegacyRaffles1+')' ;

TotalEventsAllTime += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
TotalEventsAllTime1 = String.valueOf(TotalEventsAllTime);

LegacyEvent = Integer.ValueOf(CalVouchers.Legacy_Amount_Raised_for_Events__c );
LegacyEvent1 = String.valueOf(LegacyEvent );
TotalOfLegacyEvent = TotalEventsAllTime1+' '+'('+'+'+LegacyEvent1+')';

}
}
}
}

}
return RelatedVoucherAllTime;
}

public List<Treasure_Chest_Application__c> getRTCA() {



RelatedTreasureChestApplications = new List<Treasure_Chest_Application__c>();

if(Voucherid != null && Voucherid!= ''){


for(Treasure_Chest_Application__c TreasureChests : [select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c, Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name from Treasure_Chest_Application__c where Temporary_Voucher__c =: Voucherid AND (Date_Accepted__c = LAST_N_DAYS:30 OR Date_of_the_Event__c = LAST_N_DAYS:30) ]){
// if(date.today().month() - TreasureChests.Date_of_the_Event__c.month() <= 1 && (date.today().year() == TreasureChests.Date_of_the_Event__c.year()) || (date.today().month() - TreasureChests.Date_Accepted__c .month() <= 1 && (date.today().year() == TreasureChests.Date_Accepted__c .year()))){
RelatedTreasureChestApplications.add(TreasureChests);
// }

}
}
return RelatedTreasureChestApplications;
}

}

 

Test Class For this is:

===================

 

@isTest(seeAllData = true)
Public class TestVoucherContactReport{
public Integer TotalRaffles = 0;
public Integer TotalEvents = 0;
public Integer NumberEventsBenefiting =0;
public static testMethod void testVoucherContactReport() {


Account newAcc = new Account();
newAcc.Name = 'Test Account';
newAcc.Post_Code__c = '11111';
newAcc.Address_Line_1__c = 'Test Account';
newAcc.Website = 'Test Account';
newAcc.Address_Line_2__c = 'Test Account';
newAcc.Charity_number__c = 321231 ;
newAcc.City__c = 'Test Account';
newAcc.Phone = '323424' ;
newAcc.County__c = 'Test Account';
newAcc.Where_do_we_post_your_prize_voucher__c = 'Test Account';
insert newAcc;


Voucher__c TemporaryVoucher = new Voucher__c();
TemporaryVoucher.Name = 'Manchester United Tickets';
TemporaryVoucher.Account__c = newAcc.Id;
TemporaryVoucher.Start_Date__c = date.today();
TemporaryVoucher.End_Date__c = date.today();
TemporaryVoucher.Term__c = '1 Month';
TemporaryVoucher.Legacy_Used__c = 2;
//TemporaryVoucher.Number_of_Events_Benefiting__c = 6;
TemporaryVoucher.Legacy_Amount_Raised_for_Events__c = 2;
TemporaryVoucher.Legacy_Amount_Raised_for_Vouchers__c = 8;

insert TemporaryVoucher;

System.assertEquals(TemporaryVoucher.Legacy_Used__c,2);

Contact C = new Contact();
c.LastName = 'Contact';
c.AccountId = newAcc .id;
c.Email = 'rshruthig@moldtekindia.com';
Insert C;
System.assertEquals(c.Email,'rshruthig@moldtekindia.com');

Campaign Camp = new Campaign();
Camp.Name = 'Test Campaign';
insert Camp;
System.assertEquals(Camp.Name,'Test Campaign');
Treasure_Chest_Application__c TCApp = new Treasure_Chest_Application__c();
TCApp.Amount_Raised_for_Event__c = 800.00;
TCApp.Amount_Raised_for_Voucher__c = 900.00;
TCApp.Campaign__c = '701c00000001mCx';
TCApp.Temporary_Voucher__c = 'a1Ac0000000Vb0O';
Insert TCApp;
VoucherContactReport testTreasureChest = new VoucherContactReport();
testTreasureChest.Voucherid = TemporaryVoucher.Id;
testTreasureChest.getRelatedVoucher();
testTreasureChest.getRelatedVoucher12();
testTreasureChest.getRelatedVoucher3();
testTreasureChest.getRelatedVoucher6();
testTreasureChest.getRelatedVoucherAllTime();
testTreasureChest.getRTCA();
}

}

Here I am Getting only 51% code coverage for this, can you please help any one to reach my code coverage  atleast 80%

........its an emergency.....please revert me as early as possible .....

Hi any one please help me to cover these lines.......


public with sharing class ExpenseListEditController
{

public List<ExpenseKeyWrapper> wrappers {get; set;}

public Integer addItemCount {get; set;}


public Integer keyToDelete {get; set;}

public Integer mainKey {get; set;}

public Expense_Sheet__c expSheet {get; set;}

public string idParam;

private List<Expense__c> toDelete=new List<Expense__c>();

public ExpenseListEditController()
{
mainKey=1;
addItemCount=3;


idParam = apexpages.currentpage().getparameters().get('Id');

buildexpensesheet();
}

Public void buildexpensesheet() {
wrappers=new List<ExpenseKeyWrapper>();
expSheet = [Select Name, Employee__c, Month__c, Year__c , total__c FROM Expense_Sheet__c WHERE id =:idParam];
List<Expense__c> expenses=[select id, Date__c,Receipt_Number__c, Description__c, Type__c, Amount__c, Vat_Code__c, Expense_Sheet__c from Expense__c WHERE Expense_Sheet__c = :idParam LIMIT 1000];
for (Expense__c exps : expenses)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, exps));
}
}


public PageReference addItems()
{
if ( (addItemCount>0) && (addItemCount<10) )
{
for (Integer idx=0; idx<addItemCount; idx++)
{
wrappers.add(new ExpenseKeyWrapper(mainKey++, new Expense__c()));
}
}

return null;
}


public PageReference removeItem()
{
Integer idx=0;
Boolean found=false;
for (ExpenseKeyWrapper wrap : wrappers)
{
if (wrap.key==keyToDelete)
{
found=true;
if (null!=wrap.expense.id)
{
toDelete.add(wrap.expense);
}
break;
}
else
{
idx++;
}
}

if (found)
{
wrappers.remove(idx);
}

return null;
}


public PageReference save()
{
PageReference result=null;
Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();


for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
if (String.IsBlank(wrapper.expense.Receipt_Number__c))
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;


result=new PageReference('/' + idParam);
}

return result;
}

public PageReference updatetotal()
{

Boolean error=false;
List<Expense__c> toUpsert=new List<Expense__c>();


for (ExpenseKeyWrapper wrapper : wrappers)
{
if ( (!String.IsBlank(wrapper.expense.Description__c)) )
{
if (String.IsBlank(wrapper.expense.Expense_Sheet__c))
{
wrapper.expense.Expense_Sheet__c = idParam;
}
toUpsert.add(wrapper.expense);
}
else
{
error=true;

}
}


if (!error)
{
delete toDelete;
upsert toUpsert;

}

buildexpensesheet();

return Null;
}
}

Hi i have two objects ,can any one help me to crack the relationship fields

Budget_Building__c(parent)

Budget_Line_Item__c(child)

relationbship between is Look-up

 

in child i have one field like August_Budget_Local_Amount__c how can i retrieve this field from parent....

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

Any one help me writing test class for this........

 

public with sharing class ExpenseKeyWrapper
{
public Integer key {get; set;}
public Expense__c expense {get; set;}

public ExpenseKeyWrapper(){}

public ExpenseKeyWrapper(Integer inKey, Expense__c inExpense)
{
key=inKey;
expense=inExpense;
}
}

I have two fields one date_of _last_flight__c and date_of_last_sim__c in Aircraft_Contact__c object, these two fileds should be in date format like dd-mm-yyyy other wise i have to show the error like date should be in date format.........any one suggest me writing the validation trigger for this 

Voucher is parent object and treasure_chest_application__c is my child object ,the issue is i could not able to cover the code for this in test class.......can please help to me  in writing test class for this............

 

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null ){

if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA.Date_of_the_Event__c.year())){

RelatedVoucher.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher ){
TotalRaffles = 0 ;
TotalEvents = 0 ;
NumberEventsBenefiting = 0;

for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){


// NumberEventsBenefiting += Integer.valueOf(TCA1.get('expr0'));
NumberEventsBenefiting++;
TotalRaffles += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
system.debug('&&&&&&&&&&&&&&&&&&&&&&&&&&&'+ TotalRaffles);
}
}
}
}