11

I am trying out the VS Code and wondering if it could be possible to display custom object fields while typing an apex code. At the moment the fields are not displayed:

enter image description here

But when I take some standard object like Account they are already there:

enter image description here

What is wrong?

4 Answers 4

19

Autocomplete depends on the metadata cache. To fix this, go to View > Command Palette (Ctrl-Shift-P), and type in "sobject". You should see a command "SFDX: Refresh sobject definitions." After that command runs, you should get autocomplete for all custom objects and fields.

3
  • Thank you mate! :) It is true, but I should have done additional step - add my namespace prefix to the custom objects name 8-() Mar 20, 2019 at 8:16
  • Thanks, this really helped me...
    – Srujan
    Dec 9, 2019 at 9:25
  • thank you .. was driving me nuts!
    – Etienne
    May 7, 2022 at 19:55
5

I will answer my own question because I have found the problem (I think).

The autocomplete for custom object depends on the metadata definition, like @sfdcfox said. After updating the sobjects it did not work again. The tricky part is: my org has a namespace, so I should explicitly specify the namespace prefix to the custom object name in the apex code.

It is not necessary to do this in order for the code to work, but it seems to be necessary for the vs code to make the autocompletion work :(

So with a namespace prefix it works, without it not:

enter image description here

2

Sometimes "Auto-completion" still don't work even after refresh object definitions.

It is because of the Java Home Path not configured with the VS Code.

0

I'll add a note here for anyone else who has attempted the above steps but is still experiencing issues (as I was):

Please ensure that you have the correct Salesforce permissions to access the field(s) you are trying to interact with in VS Code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .