[SalesForce] Unexpected token trigger

I keep getting Error: Compile Error: unexpected token: 'trigger' at line 1 column 0 with this simple trigger

    trigger CreateWorkRecordsX on Staff_Week_Plan_Creator__c (after insert) {        

        List <Staff_work_records__c>  WR1 = new List <Staff_work_records__c> ();

        for(Staff_Week_Plan_Creator__c o:trigger.new)
        {

            WR1.Report_Date__c=o.Start_Date_of_Week__c;

        }
                insert WR1;
}

Purpose of this trigger is to create new Staff_work_records__c record after Staff_Week_Plan_Creator__c has been inserted.

Very new to apex, any ideas?

Best Answer

This error appears when you try to create an Apex Class with an Apex Trigger code. Those two metadata types are syntax-similar, but they are totally different. Check if you are trying to save this trigger as .apxc in your developer console. If so, then that's your issue. You should save an .apxt instead.

Example:

enter image description here

The file on the left is a class, and the one in the right is a trigger.

Your code was wrong too, just like itzmukeshy7 said. But I think that if this error appears after you made the suggested modifications, then I think my post will help you now.

Related Topic