You need to sign in to do that
Don't have an account?
kumar 197
Can Anyone help me write Test Class for this???
<apex:page controller="FlightController">
<apex:pageBlock title="Select Flights">
<apex:form >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputText value="Flights"/>
<apex:selectList size="1" value="{! fosId }">
<apex:selectOptions value="{! fosList }"/>
<apex:actionSupport event="onchange" reRender="FL01"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
<apex:pageBlock id="FL01">
<apex:detail subject="{!fosId}" relatedlist="True"/>
<apex:relatedList list="Booking__c"/>
</apex:pageBlock>
</apex:page>
--------------------------------------------
public class FlightController {
public List<SelectOption> flights = new List<SelectOption>();
public Id fosId {get;set;}
public List<SelectOption> getfosList(){
for(Flight__c fos : [SELECT Id, Name,(SELECT Name,Id FROM Bookings__r ORDER BY BoardingDate__c DESC) FROM Flight__c]){
flights.add(new SelectOption(fos.Id, fos.Name));
}
return flights;
}
}
<apex:pageBlock title="Select Flights">
<apex:form >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputText value="Flights"/>
<apex:selectList size="1" value="{! fosId }">
<apex:selectOptions value="{! fosList }"/>
<apex:actionSupport event="onchange" reRender="FL01"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
<apex:pageBlock id="FL01">
<apex:detail subject="{!fosId}" relatedlist="True"/>
<apex:relatedList list="Booking__c"/>
</apex:pageBlock>
</apex:page>
--------------------------------------------
public class FlightController {
public List<SelectOption> flights = new List<SelectOption>();
public Id fosId {get;set;}
public List<SelectOption> getfosList(){
for(Flight__c fos : [SELECT Id, Name,(SELECT Name,Id FROM Bookings__r ORDER BY BoardingDate__c DESC) FROM Flight__c]){
flights.add(new SelectOption(fos.Id, fos.Name));
}
return flights;
}
}
@isTest
private class FlightControllerTest {
@isTest static void myTest() {
Flight__c f = new Flight__c();
f.Name = 'Test Flight';
insert f;
Customer__c c = new Customer__c();
c.Name = 'Testc';
insert c;
Booking__c b =new Booking__c();
// b.Name='Test Bookings';
b.Flight__c = f.Id;
b.Customer__c= c.Id;
Insert b;
pagereference testPage=page.FlightController;
FlightController fc = new FlightController();
fc.fosId = f.Id;
fc.getfosList();
}
}
All Answers
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!
I tryed your code but but getting error : Field not writeable:Booking__c.Name .So i allow the reparenting on both master Flight__c and Customer__c but its not working yet. Here Booking is the Junction between flight and customer.
@isTest
private class FlightControllerTest {
@isTest static void myTest() {
Flight__c f = new Flight__c();
f.Name = 'Test Flight';
insert f;
Customer__c c = new Customer__c();
c.Name = 'Testc';
insert c;
Booking__c b =new Booking__c();
// b.Name='Test Bookings';
b.Flight__c = f.Id;
b.Customer__c= c.Id;
Insert b;
pagereference testPage=page.FlightController;
FlightController fc = new FlightController();
fc.fosId = f.Id;
fc.getfosList();
}
}