Cannot Parse APEX Class - SOQL query WITH SECURITY_ENFORCED

Hello,

We are using SonarLint as a plugin for VS Code to Analyse APEX class. We also use Sonarcloud during the build pipeline.

We ran into these errors with recent build on couple of Apex classes, the error says, it can’t parse the file. After doing some research, we found that SonarCloud was not able to understand the keyword “WITH SECURITY_ENFORCED” which is part of SOQL query in Apex class. I removed this keyword and everything works fine. We will need this keyword for SOQL field/object level security.

12:15:36.262 ERROR: Unable to parse file: file:///C:/agent/_work/1/s/force-app/main/default/classes/TermsAndConditionsController.cls. Parse error at position 7:0 12:15:36.262 ERROR: Cannot parse ‘force-app/main/default/classes/TermsAndConditionsController.cls’: ParseException: Syntax(error = UnexpectedToken(loc = (7, 1, 2, 8), token = ‘public’))

Keyword used in Apex class
Terms_and_Conditions__c termsAndConditions =
[SELECT Id, Copy__c, Name, Short_Copy__c
FROM Terms_and_Conditions__c
WHERE Name =: name
AND Product__r.Name =: productName
AND Status__c =: Constants.TERMS_AND_COND_STATUS_ACTIVE
WITH SECURITY_ENFORCED
];

Can you please let me know any resolutions?

Thanks for your time.