0

I'm using VSCode with Github and Deploying to a Sandbox. When I save my classes, VSCode lists problems which don't exist and which don't clear when the class is deployed successfully. For example, all custom objects are invalid types. I can deploy the class with no problems and I can paste it into the developer console for the default org with no problems reported. What do I need to do get VSCode to validate my Apex against my default org?

My settings.json:

{
  "salesforcedx-vscode-core.push-or-deploy-on-save.enabled": true,
  "search.exclude": {
    "**/node_modules": true,
    "**/bower_components": true,
    "**/.sfdx": true
  },
  "eslint.nodePath": "/Users/***/.vscode/extensions/salesforce.salesforcedx-vscode-lwc-46.10.0/node_modules",
  "editor.fontSize": 14,
  "salesforcedx-vscode-core.retrieve-test-code-coverage": true,
  "salesforcedx-vscode-core.show-cli-success-msg": true
}

Sample problems list: enter image description here

1

You need to refresh your sObject definition cache. Select your project, go to the command palette (View > Command Palette), and type in "sobject". You should see an option called "SFDX: Refresh SObject Definitions". Using this feature will refresh your metadata definitions, and should remove the errors about "Invalid Types."

  • Still getting erroneous problems, but now new and different ones. For example, String externalID = EncodingUtil.convertToHex(hash).substring(0,18); yields "variable does not exist, EnclodingUtil." It's like I need Java package delcarations. – Cleverlemming Aug 19 at 17:12
  • 1
    @Cleverlemming There's a typo in that name (EncodingUtil vs EnclodingUtil). That said, assuming it's just a typo here and not in your code, it might be a corrupt code cache or something. I just checked in my org's code and everything appears to be in order. Try creating a new project, building from a manifest, and/or updating all extensions and the CLI to the latest version. It should be working just fine. – sfdcfox Aug 19 at 17:55
0

The issue was the enable-semantic-errors setting under Settings -> extensions -> Salesforce Apex. Unchecking this setting solved my problem. It's currently in beta. I hope this saves someone a little time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.