[SalesForce] VS Code and Sandbox

It is ok to say 'forget it, it doesn't work with a sandbox'. So I have successfully created a project and done a retrieve source from org. I'm focusing on APEX classes for the moment. I can open, edit, save, and update the sandbox copy of the class with a deploy source to org.

Here's the strange thing:

If I create a new class in my sandbox and then do a retrieve source from org the new class is not picked up.
If I create the class in VS Code and do a deploy source to org the new class is pushed over to the sandbox.
If I update the class in the sandbox and do a retrieve OR update the class in VS Code and do a deploy then everything works as I would expect.

I initially thought is was this 'source of truth' idea but I don't think so. Thoughts?

Best Answer

The sfdx force:source:retrieve command requires one of three parameters: a metadata file, a list of metadata objects, or a source path. The sourcepath option is generally the safest to use when working on a DX project to avoid accidentally pulling files you didn't mean to, without specifying a metadata file or potentially long list of file names.

The extension you're using presumes that you want to just pull the source for files you already have on your system. For other types of pulls, you can do this directly through the terminal. For example, to pull a specific class:

sfdx force:source:retrieve --metadata ApexClass:MyNewClass

The new CLI uses the same metadata types as the Metadata API, so you might want to start there for a reference of types, plus the sfdx help force:source:retrieve command for more information on how this command works.

If you don't have a menu option for retrieving specific files, you can click on the TERMINAL tab to open a new command prompt, then type in the sfdx command you'd like to use.

Alternatively, definitely use the Create Apex Class option from your context menu to create it locally then push it to the server. That's how the extension is configured to work, so it'd be easiest to just follow the path of least resistance.

Xi Xiao has also written a gist that you may find useful for commands you're likely going to want to get started.

Related Topic