You need to sign in to do that
Don't have an account?
Search with in a Search
Hi,
This code pulls back via a VF page availability within date range (start and end date). It list room allocations which as an object has a lookup to a room record on the room object..
I would like to run a second query based on the first.
For the rooms that a brought back i.e rooms allocated I would like to bring back a separate list rooms not allocated. Room__c highlighted below is the lookup to the room__c object.
So I think using the list of room allocation from the first query I will know the room__c for each record. I want to use the room_c name against the room object to show rooms that are not in that list.
So on the VF page I will have two list rooms allocated and rooms not allocated within a give date range.
Any help would be great.
Thanks
Ross
Public class Roommanager { public PageReference room() { return null; } public Room_Allocation__c room {get;set;} public roommanager(ApexPages.StandardController controller) { room=(Room_Allocation__c)controller.getRecord(); } public List<Room_Allocation__c> getRooms(){ List<Room_Allocation__c> listBd=[select Id, Name, Start_Date__c, End_Date__c, Nights__c, Room__c, Reservation__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)]; return listBd; } }
All Answers
If I've understood that right, then this should do it :
List<Id> allocatedRooms = new List<Id>;
for(Room_Allocation__c allocRooms : getRooms() )
allocatedRooms.add(allocRooms.Room__c);
List<Room_c> unallocatedRooms = [Select Id, Name, (Select Id, Name, Start_Date__c, End_Date__c from Room_Allocations__r) from Room__c where Id NOT IN :allocatedRooms];
I've added an inner query for querying Room Allocations for Unallocated Rooms, in case you wanted to access Allocations at dates not in the range.
Thanks for this very new to APEX, although I am web designer / longterm SFDC admin.
I get a System.LimitException: Too many SOQL queries: 101 with a lot of errors, code is below probably my fault.
Any thoughts welcome.
Thanks
Ross
Salesforce has some governor limits - in order to ensure efficient usage of code and/or resources.
It seems like your SOQL queries are being executed in a loop, which is causing it to exceed the 100 SOQL query limit.
Please check the source of this loop - it could also be the apex:repeat tag in your VF page calling the method in a loop.
Thanks I started to read about limits but as mentioned I am very new to APEX.
I don't have a repeat in VF Page as you can see code below.
I am a bit lost to say the least.
Sorry I am probably not understanding. The code produces no errors however the Booked Room table no longer works all records are returned.
I have added to my VF page to display the second table all new code below. Not sure what is going wrong.
Thanks so much, I now understand how the inner query works.
Brilliant.
Cheers
R
Awesome! Cheers mate :D