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
madhusudan22911.396875437459208E12madhusudan22911.396875437459208E12 

Not able to use comparision operator in SOQL query

Hello There,
I am novice in Salesforce.
I am having two Objects Property__c and Contacts(In My Case it is Buyer), I am establishing many-2-many relationship between these two Objects with a Juction Object as 'PropertyBuyer__c'. I want after any property is saved filter Contacts from database(depends upon the criteria) and create a new record in Junction Object 'PropertyBuyer__c'
Following is my code
trigger Rename on Property__c (Before Insert, Before Update) {
   
    list<id> contactids = new list<id>();
    list<PropertyBuyer__c> property_buyer_list = new list<PropertyBuyer__c>();
    Decimal prop_price;
    String prop_city;
    for(Property__c prop_obj:Trigger.new)
    {
        prop_price = prop_obj.Price__c;
        prop_city = prop_obj.City__c;
        contactids = [SELECT id FROM Contacts WHERE Budget_From__c >= prop_price AND Budget_To__c <= prop_price AND City__c = prop_city];
        for(id con_id:contactids)
        {
            PropertyBuyer__c PB_obj = new PB_obj();
            PB_obj.Name = prop_obj.Name;
            PB_obj.Contact__c = con_id;
            PB_obj.Property__c = prop_obj.id;
            property_buyer_list.Add(PB_obj);
        }
    }
    Insert property_buyer_list;
}

But I am gettign following error Error: Compile Error: unexpected token: 'prop_price' at line 11 column 70
Please Help me soon

Thanks & Regards
Madhusudan Singh
madhusudan22911.396875437459208E12madhusudan22911.396875437459208E12

I have updated my code as there were few more error

Updated code is 
trigger Rename on Property__c (Before Insert, Before Update) {
  
    list<Contact> contactids = new list<Contact>();
    list<PropertyBuyer__c> property_buyer_list = new list<PropertyBuyer__c>();
    Decimal prop_price;
    String prop_city;
    for(Property__c prop_obj:Trigger.new)
    {
        prop_price = prop_obj.Price__c;
        prop_city = prop_obj.City__c;
        contactids = [SELECT id FROM Contact WHERE Budget_From__c >= 0 AND Budget_To__c <= 500000 AND City__c = 'City1'];
        for(Contact con_id:contactids)
        {
            PropertyBuyer__c PB_obj = new PropertyBuyer__c ();
            PB_obj.Name = prop_obj.Name;
            PB_obj.Contact__c = con_id.id;
            PB_obj.Property__c = prop_obj.id;
            property_buyer_list.Add(PB_obj);
        }
    }
    Insert property_buyer_list;
}

But In My query I am using static variable instead it should use prop_price and prop_city

Regards

andy21aaandy21aa
try:

contactids = [SELECT id FROM Contacts WHERE Budget_From__c >= :prop_price AND Budget_To__c <= :prop_price AND City__c = :prop_city];
madhusudan22911.396875437459208E12madhusudan22911.396875437459208E12
Thanks andy It Work Thanks a lot