Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For variable with @testvisible when accessed from test class I am getting warning "Variable is not visible: CustomerSurveyTH.forceException" #6055

Open
PawelWozniak opened this issue Feb 4, 2025 · 3 comments

Comments

@PawelWozniak
Copy link
Contributor

PawelWozniak commented Feb 4, 2025

Summary

I have a those lines in CustomerSurveyTH

@TestVisible
private static boolean forceException = false;

Then I have a code in CustomerSurveyTH_Test

CustomerSurveyTH.forceException = true;

In the Problems section I am getting the warning "Variable is not visible: CustomerSurveyTH.forceException".

Yes, it is a private variable, but it has @testvisible annotation and is accessed from the test class, which is annotated with @isTest and the test method. So all is correct, and on save, the compiler is not showing an error as well as at runtime there are no errors.

Steps To Reproduce:

  1. In trigger handler create variable:
@TestVisible
private static boolean forceException = false;
  1. In test class use this code"
CustomerSurveyTH.forceException = true;
  1. Save both. In the problem area in VSCode, you will see "Variable is not visible: CustomerSurveyTH.forceException"

Expected result

No errors as the code is compiling and running without issues.

Actual result

Getting a misleading error.

Additional information

Image Image

Salesforce Extension Version in VS Code: 62.14.1

Salesforce CLI Version: @salesforce/cli/2.74.6 win32-x64 node-v22.13.1

OS and version: Windows 11

VS Code version: 1.96.4

Most recent version of the extensions where this was working: none.

@svc-idee-bot
Copy link
Collaborator

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

@svc-idee-bot
Copy link
Collaborator

Hello @PawelWozniak 👋 It looks like you didn't provide all the required basic info in your issue.

If you haven't already, please provide the following info:
Salesforce Extension Version in VS Code:
Salesforce CLI Version:
OS and version:
VS Code version:
Most recent version of the extensions where this was working:

Here's an example of a set of required info that will pass the validation:
Salesforce Extension Version in VS Code: 60.13.0
Salesforce CLI Version: @salesforce/cli/2.42.6 darwin-arm64 node-v18.18.2
OS and version: MacOS Sonoma 14.5
VS Code version: 1.89.1
Most recent version of the extensions where this was working: 60.11.0

A few more things to check:

  • Make sure you've provided detailed steps to reproduce your issue, as well as all error messages that you see.
    • A repository that clearly demonstrates the bug is ideal.
    • Error messages can be found in the Problems Tab, Output Tab, and from running Developer: Toggle Developer Tools in the command palette.
  • Make sure you've installed the latest version of the Salesforce Extension Pack for VSCode. (docs)
  • Search GitHub for existing related issues.

Thank you!

@mingxuanzhangsfdx
Copy link
Member

Hi @PawelWozniak , by mentioning

So all is correct, and on save, the compiler is not showing an error as well as at runtime there are no errors.

do you mean when you save both files, the compiler problem disappears?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants