function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tin013Tin013 

To return more than one row

 

kcList = [Select i.CurrencyIsoCode,i.Club_Type__c,i.Minimum_Age__c, i.Maximum_Spaces__c, i.Maximum_Age__c, 
            i.Id, i.Hotel_Club__r.EndDate, i.Hotel_Club__r.Club_Name__c,  
            i.Hotel_Club__r.Closing_Days__c,i.Hotel_Club__r.StartDate,i.Hotel_Club__c ,
            i.Opening_Hours__c,i.Cost__c,i.Age_Range__c
            From Inventory_Product__c i 
            where i.Hotel_Club__r.StartDate <= :sDate 
              and  i.Hotel_Club__r.EndDate >= :sDate
              and i.Hotel_Club__r.AccountId = :hotelSelected
              ];

 

Hi all,

 

I don't know much about coding but I have the following query which returns a row. But if there is more than one return it only returns the first row. I am just wondering if there is a way to capture more than one rows into kcList?

 

Any help would be much appreciated.

 

kcList = [Select i.CurrencyIsoCode,i.Club_Type__c,i.Id, i.Hotel_Club__r.EndDate, i.Hotel_Club__r.Club_Name__c,              i.Hotel_Club__r.Closing_Days__c,i.Hotel_Club__r.StartDate,i.Hotel_Club__c ,            i.Opening_Hours__c,i.Cost__c,i.Age_Range__c            From Inventory_Product__c i             where i.Hotel_Club__r.StartDate <= :sDate               and  i.Hotel_Club__r.EndDate >= :sDate              and i.Hotel_Club__r.AccountId = :hotelSelected ];

 

Many thanks

Shailesh DeshpandeShailesh Deshpande

that is because  of the condition in your where clause

 

i.Hotel_Club__r.AccountId = :hotelSelected;

 

assuming that hotelSelected is an Id

 

every record has a unique id and so it returns u only the record with the id  = i.Hotel_Club__r.AccountId;..... remove that condition and your code will work fine.....

Tin013Tin013

Hi there,

 

Many thanks for your reply. I don't think I had explained well.

 

The condition below as it is can reply more than one return rows.

 

By that the I meant if the user type in 03/05/2010 as Start date and 11/03/2010 as End date and the inventory has the following entries:

- 01/05/2010 as Start Date and 07/05/2010 as End date

- 08/05/2010 as Start Date and 15/05/2010 as End date

 

Surely in this case, kcList should have two entries.

 

I would like to know how I can loop the query and assign the data into kcList.

 

kcList = [Select i.CurrencyIsoCode,i.Club_Type__c,i.Id, i.Hotel_Club__r.EndDate, i.Hotel_Club__r.Club_Name__c,              i.Hotel_Club__r.Closing_Days__c,i.Hotel_Club__r.S tartDate,i.Hotel_Club__c ,            i.Opening_Hours__c,i.Cost__c,i.Age_Range__c            From Inventory_Product__c i             where i.Hotel_Club__r.StartDate <= :sDate               and  i.Hotel_Club__r.EndDate >= :sDate              and i.Hotel_Club__r.AccountId = :hotelSelected ];

 

If anyone can reply back to me on this, I would extremely appreciate it.

 

Regards

Shailesh DeshpandeShailesh Deshpande

can you tell me what is hotelSelected...?

Deer altanDeer altan
Great to see this script. I really want to use the scirpt code for my business of Gclub (https://gclubdealer.com/).