0

I am new to VSCode.

I have set up VSCode and connected it an Org.

But not able to see the classes from the Org in the VSCode.

I need to use classes, triggers and VF pages from the Org, in VSCode?

I right clicked on force-app folder and then clicked on SFDX: Retrieve Source from Org:

enter image description here

Got message like this in output:

sfdx force:source:retrieve --sourcepath c:\Users\MyUser\Documents\Projects\MyProject\MyProject\force-app ended with exit code 0
=== Retrieved Source
No results found

I tried retrieving files from Org in the MyProject->.sfdx->org->firstname.lastname@domain.com like this:

enter image description here

Getting the following error in output:

Error deploying or retrieving source: The file or directory that you tried to deploy or retrieve isn't in a package directory that's specified in your sfdx-project.json file. Add this location to your "packageDirectories" value, or deploy or retrieve a different file or directory. For details about sfdx-project.json, see: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm

What I am missing here?

1

Create package.xml file as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>*</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexPage</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexTrigger</name>
    </types>
    <version>46.0</version>
</Package>

Save the above file in either src or force-app folder. This depends on how you created project. (sfdx creates force-app and forcecode extension creates src folder)

Then you can use sfdx force:source:retrieve -x src/package.xml in vs code terminal to retrieve files mentioned in package. (-x is the path to package.xml)

For example, below is folder structure when project is created using forceCode extension.

enter image description here

You need to be in the project to get it.

Wait for 1-2 minutes.

You will see list of imported files.

Refresh the explorer:

enter image description here

You will be able to see apex classes under the classes under force-app\main\default\classes similarly triggers and other components

There are other direct ways of getting like below:

sfdx force:source:retrieve -m CustomObject,ApexClass

sfdx force:source:retrieve -m ApexClass:MyApexClass

You can get the commands from https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_source.htm

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.