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
Smita HodiggeriSmita Hodiggeri 

unexpected token 'trigger' on creating new trigger in Visual studio code

Hi Community,
I am writing a brand new trigger on visual stuio code by going under triggers--> create new apex trigger and all iI have in the trigger(No test class yet) is as below. 

trigger AccountTrigger on Case (before insert) {
System.debug('I am in trigger please confirm I am here');

and it throws error as follows. 
Unexpected token trigger at Ln1,Col 1 
Can i get some pointers on how to resolve this in Visual studio ?
The Same code in Dev console has no issues. 
Thanks in advance, 
Smita
SwethaSwetha (Salesforce Developers) 
HI Smita,
It looks like aa syntax issue or misconfiguration in your VS Code environment. Try these troubleshooting steps:
>Ensure that you have the latest version of the Salesforce Extensions for VS Code installed. You can check for updates in the VS Code Extensions tab.

>Ensure you have the latest versions of Salesforce CLI (SFDX CLI) installed and that you have the Salesforce CLI plugin enabled in your VS Code.

> Make sure you have a valid Salesforce DX project set up in your workspace. You can use the "SFDX: Create Project with Manifest" command in VS Code to create a new Salesforce DX project or open an existing one.

Check Project Scratch Org or Default Org: Ensure you have a valid scratch org or default org set as the active Salesforce Org for your project. You can use the "SFDX: Set a Default Org" or "SFDX: Create a Default Scratch Org" command in VS Code to set or create a default org.

>You mentioned that the same code works fine in Developer Console. To validate your code in Developer Console, open the Developer Console, go to the "Debug" tab, and click "Open Execute Anonymous Window." Then paste your trigger code and execute it. This will help you verify that your trigger code is valid.

> After ensuring your Salesforce DX project is set up correctly, try saving the trigger file (e.g., AccountTrigger.trigger) from VS Code to your Salesforce org using the "SFDX: Deploy Source to Org" command. This will help confirm that the code is valid and can be deployed to Salesforce.

If this information helps, please mark the answer as best. Thank you