You need to sign in to do that
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
Need help? DismissYou need to sign in to do that
Don't have an account?
Hi, Please help on writing test case to get 100% code coverage . Lines in Red not covered
Here is the Apex class
public with sharing class TestFlighRequestPage {
Test_Flight_Request__c fr;
public List<Opportunity> listOpp;
public String Id {get; set;}
private string result;
public TestFlighRequestPage(ApexPages.StandardController stdController)
{
fr = (Test_Flight_Request__c)stdController.getRecord();
if(fr.Id == null)
Id = ApexPages.currentPage().getParameters().get('opp');
else
Id = fr.Opportunity__c;
listOpp = [SELECT id ,Name, Departure_Date__c,Number_of_Passengers__c,Destination_Zone__c,Return_Date__c,
Origin_City__c,Destination_City__c,Flexibility_From__c,Flexibility_To__c
FROM Opportunity WHERE Id = :Id];
if(listOpp.size() >0)
{
if(fr.Opportunity__c == null)
{
fr.Opportunity__c = listOpp[0].Id;
}
if (fr.From__c == null)
{
fr.From__c = listOpp[0].Origin_City__c;
}
if (fr.To__c == null)
{
fr.To__c = listOpp[0].Destination_City__c;
}
if (fr.Outbound_del__c == null)
{
fr.Outbound_del__c = listOpp[0].Departure_Date__c;
}
if (fr.Pax_del__c == null)
{
fr.Pax_del__c = listOpp[0].Number_of_Passengers__c;
}
if (fr.Region_del__c == null)
{
fr.Region_del__c = listOpp[0].Destination_Zone__c;
}
if (fr.Inbound_del__c == null)
{
fr.Inbound_del__c = listOpp[0].Return_Date__c;
}
if (fr.Outbound_Flexibility__c == null)
{
fr.Outbound_Flexibility__c = listOpp[0].Flexibility_From__c;
}
if (fr.Inbound_Flexibility__c == null)
{
fr.Inbound_Flexibility__c = listOpp[0].Flexibility_To__c;
}
}
}
public PageReference Save()
{
try
{
if(fr.Id ==null)
insert fr;
else
update fr;
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
PageReference pr = new PageReference('/'+ Id);
pr.setRedirect(true);
return pr;
}
public PageReference SaveAndNew()
{
try
{
if(fr.Id ==null)
insert fr;
else
update fr;
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
PageReference pr = new PageReference('/' + Id);
pr.setRedirect(true);
return pr;
}
public void SendItineryEmail()
{
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://itinerary.swiftsetup.com/ItineraryBuilder/GetCustomerView?opportunityId='+fr.Opportunity__c+'&flightRequestID='+fr.Id);
req.setMethod('GET');
HttpResponse res = h.send(req);
result = res.getBody();
String[] toaddress = new String[]{};
toaddress.add('anil@swiftsetup.com');
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toaddress);
mail.setSubject('Flight Stat');
mail.setHtmlBody(result);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
public PageReference CloneFlightRequest()
{
try
{
Test_Flight_Request__c clFR = new Test_Flight_Request__c();
Test_Flight_Request__c oldFR = [SELECT From__c, To__c,Outbound_del__c,Pax_del__c,Region_del__c,
Inbound_del__c,Outbound_Flexibility__c,Inbound_Flexibility__c,Opportunity__c,
Budget__c,Publish_Fare__c
FROM Test_Flight_Request__c WHERE Id = :fr.Id];
clFR.From__c = oldFR.From__c;
clFR.To__c = oldFR.To__c;
clFR.Outbound_del__c = oldFR.Outbound_del__c;
clFR.Pax_del__c = oldFR.Pax_del__c;
clFR.Region_del__c = oldFR.Region_del__c;
clFR.Inbound_del__c = oldFR.Inbound_del__c;
clFR.Outbound_Flexibility__c = oldFR.Outbound_Flexibility__c;
clFR.Inbound_Flexibility__c = oldFR.Inbound_Flexibility__c;
clFR.Opportunity__c = oldFR.Opportunity__c;
clFR.Budget__c = oldFR.Budget__c;
clFR.Publish_Fare__c = oldFR.Publish_Fare__c;
insert clFR;
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
PageReference pr = new PageReference('/' + Id);
pr.setRedirect(true);
return pr;
}
}
Can you post your test class, so that someone will help you to increase 100% code coverage.
some one is working on your issue.Once he wil do i will post the solution