• madhusudan22911.396875437459208E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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
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