You need to sign in to do that
Don't have an account?

Test Method Help
I got a lot of help from people on this one a few months back so thanks to all. Testing has gone well, I have made some changes and I am ready to push into live.
I now need to write a test script and I have no idea how to begin. Any code snippets / pointers would be helpful. I rarely have to write APEX code but had not choice on this occasion. Thanks again
public class Roommanager { public void search() { // Provide default values in the event that no dates are selected if(room.Search_Start_Date__c==null) room.Search_Start_Date__c=System.today().toStartOfMonth(); if(room.Search_End_Date__c==null) room.Search_End_Date__c=System.today().toStartOfMonth(); // Swap the dates if start is before end if(room.Search_Start_Date__c>room.Search_End_Date__c) { Date tempDate = room.Search_Start_Date__c; room.Search_Start_Date__c = room.Search_End_Date__c; room.Search_End_Date__c = tempDate; } // Remove previous search results rooms.clear(); availableRooms.clear(); // Find all the room allocations, add them to the list rooms.addAll( [SELECT Id, Name, Start_Date__c, End_Date__c, Nights__c, Room__c, Room__r.Room_No__c, Room__r.Lodge__c, Reservation__c, Reservation__r.Reservation_Contact__c FROM Room_Allocation__c r WHERE ( (Start_Date__c >= :room.Search_Start_Date__c AND Start_Date__c <= :room.Search_End_Date__c) OR (End_Date__c >= :room.Search_Start_Date__c AND End_Date__c <= :room.Search_End_Date__c) OR (Start_Date__c <= :room.Search_Start_Date__c AND End_Date__c >= :room.Search_End_Date__c)) ORDER BY Room__r.Lodge__c ASC,Room__r.Room_No__c ASC, Room__r.Lodge__c ASC]); // Build a list of allocated rooms Set<Id> allocatedRooms = new Set<Id>(); for(Room_Allocation__c roomAlloc:rooms) allocatedRooms.add(roomAlloc.Room__c); // Add the rooms that are still available availableRooms.addAll( [SELECT Id, Name, Room_No__c, Lodge__c, Doubles__c, Singles__c, Style__c, Normal_PAX__c, (SELECT Id, Name, Start_Date__c, End_Date__c, Room__c FROM Room_Allocations__r) FROM Room__c WHERE Id NOT IN :allocatedRooms ORDER BY Lodge__c ASC, Room_No__c ASC] ); } public Room_Allocation__c room; public List<Room_Allocation__c> rooms { get; set; } public List<Room__c> availableRooms { get; set; } // Constructor initialize memory variables public Roommanager(ApexPages.StandardController controller) { room=(Room_Allocation__c)controller.getRecord(); rooms=new List<Room_Allocation__c>(); availableRooms = new List<Room__c>(); // Default search. search(); } }
Follow these instructions to writing test class for your code
All Answers
Follow these instructions to writing test class for your code
Thanks this was just the structure I was looking for.
Your welcome Laytro. Please ask if any issue comes in test class creation.