Skip to content

Apex Language Server: Semantic errors incorrectly displaying #6081

@k-capehart

Description

@k-capehart

Summary

I've noticed a couple places where semantic errors are highlighted in VSCode incorrectly.

For example, methods on the CustomSetting apex class (such as getOrgDefaults())always show with the error: Method does not exist or incorrect signature.

Another example is referencing a private method annotated with @TestVisible from a test class shows the error: Method is not visible.

Steps To Reproduce:

Private Methods

  1. In a Salesforce project, ensure Salesforcedx-vscode-apex: Enable-semantic-errors is checked in VS Code settings
  2. Create an Apex Class with a private method and annotated with @TestVisible
public with sharing class ExampleClass {
  @TestVisible
  private static Integer addTwoNumbers(Integer a, Integer b) {
    return a+b;
  }
}
  1. Create another Apex Class to test the first one
@isTest
public with sharing class ExampleClassTest {
  @isTest
  static void testAddTwoNumbers() {
    Integer result = ExampleClass.addTwoNumbers(2, 3);
    Assert.areEqual(5, result);
  }
}
  1. addTwoNumbers is underlined with the following error: Method is not visible: Integer ExampleClass.addTwoNumbers(Integer, Integer)

Custom Settings

  1. In a Salesforce project, ensure Salesforcedx-vscode-apex: Enable-semantic-errors is checked in VS Code settings
  2. Create a CustomSetting in your Salesforce org called Trigger_Settings
  3. Create an Apex Class that references the CustomSetting and attempts to get the org defaults.
public with sharing class ExampleClassTwo {
  public static void main() {
    Trigger_Settings__c ts = Trigger_Settings__c.getOrgDefaults();
  }
}
  1. getOrgDefaults is underlined with the following error: Method does not exist or incorrect signature: getOrgDefaults from the type Trigger_Settings__c

Expected result

Neither scenario should show a semantic error, as the classes will successfully deploy and execute.

Actual result

VS Code shows semantic errors.

Additional information

Salesforce Extension Version in VS Code: 62.14.1

Salesforce CLI Version: @salesforce/cli/2.76.7 darwin-arm64 node-v20.18.0

OS and version: macOS 15.3 (24D60)

VS Code version: 1.97.1 (Universal)

Most recent version of the extensions where this was working: N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions