[SalesForce] Apex Error message: Error: Compile Error: Unexpected token ‘<'

I've created a trigger to populate Field 1 on Object 1 with Field 2 from Object 2 – when Field 2 is being created.
But I am having troubles saving it. I am getting an error message:

"Error: Compile Error: Unexpected token '<'. at line 10 column 6 ".

I am new to Apex, so I am not sure what I am missing, so a bit of help would be appreciated.

*I have created a lookup relationship between the 2 objects.

Please see below the trigger:

trigger updatefield1 on Object_2__c (before insert, before update){

    List<Object_1__C> Obj1IDs = new List<Object_1__C>();

    for(Object_2__c obj: trigger.new){
        Obj1IDs.add(Ite.Object_1__c);
    }
    List <Object_1__c> obj1s = new List <Object_1__c> ([select id, field_1__c from Object_1__c, where id in: Obj1IDs]); - //this is line 10 - where the error is

    for (Object_2__c obj: trigger.new){
        for  (integer i=0; i < obj1s.size(); i++){

            if (obj.Object_1__c == obj1s[i].id{
                obj1s[i].field_1__c = field_2__c;
            }
        }
    }
    update obj1s;
}

Best Answer

There is a comma after the object name in the SOQL. remove that from Object_1__c,

List <Object_1__c> obj1s = new List <Object_1__c> ([select id, field_1__c from Object_1__c where id in: Obj1IDs]);
  • //this is line 10 - where the error is