I was wondering if I could have some advice on SOQL queries, I want to return a list to show in a visualforce page of all records that are similar (not related) to each other.
So I'm querying by using the current record's values..
public FilteredListingsController (ApexPages.StandardController sc) {
sc.AddFields(new List<String>{'Commercial_Or_Residential__c','Bathrooms__c','Bedrooms__c','PropertyListingType__c','Property__r.Postcode__c','Property_Address__c','Property__r.Type_of_Property__c', 'Building_Type__c','Sale_Price__c','RentAmount__c'});
CurrentListing = (PropertyListing__c) sc.getRecord();
recordId = ApexPages.currentPage().getParameters().get('id');
Listings = [SELECT Name, Id, Area__c, Settlement_Date__c, Bedrooms__c, Property__r.State__c ,Leased_Date__c, Stage__c, Property__r.Type_of_Property__c,Sale_Price__c,RentAmount__c, Property__r.Street__c, Property__r.City__c , PropertyListingType__c,
Property__r.Postcode__c,Bathrooms__c, Building_Type__c, Property_Address__c, Commercial_Or_Residential__c FROM PropertyListing__c WHERE Commercial_Or_Residential__c =:CurrentListing.Commercial_Or_Residential__c AND (Bedrooms__c=:CurrentListing.Bedrooms__c OR Bathrooms__c=:CurrentListing.Bathrooms__c) AND PropertyListingType__c =:CurrentListing.PropertyListingType__c
AND Property__r.Postcode__c=:CurrentListing.Property__r.Postcode__c AND ((Sale_Price__c <=:CurrentListing.Sale_Price__c*1.3 AND Sale_Price__c >=:CurrentListing.Sale_Price__c*0.8) OR (RentAmount__c <=: CurrentListing.RentAmount__c*1.5 AND RentAmount__c >=: CurrentListing.RentAmount__c*0.8))AND Property__r.Type_of_Property__c Includes (:CurrentListing.Property__r.Type_of_Property__c)];
system.debug(Listings)
}
I think this is where i'm failing:
AND ((Sale_Price__c <=:CurrentListing.Sale_Price__c*1.3 AND Sale_Price__c >=:CurrentListing.Sale_Price__c*0.8) OR (RentAmount__c <=: CurrentListing.RentAmount__c*1.5 AND RentAmount__c >=: CurrentListing.RentAmount__c*0.8))
I'm not too sure if you can directly multiply values within the query. For example I wanted all properties that are between 80% -130% of the listed sale price or 80% -150% of the listed rent amount.
any advice would be mega, Cheers mike.
Edit.
Thanks for the help. I removed any white spaces in the query. and created separate variables for the values and it seems to have worked a treat. Thanks for your help.