salesforcedx-vscode
salesforcedx-vscode copied to clipboard
SFDX: Retrieve Source from Org command does not retrieve new files
Bug 1175 was closed without the bug being fixed.
Steps To Reproduce:
- Download Source from Org.
- Create new apex class in browser.
- Retrieve Source From Org
Expected result
The new class appears in the explorer view.
Actual result
The new class does not appear.
My package.xml
Version of VSCode:
Version: 1.45.1 (user setup) Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a Date: 2020-05-14T08:27:35.169Z Electron: 7.2.4 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 10.0.17763
I don't know if its a bug in my case I need to do a retrieve in the package when a need a new file from org, the retrieve button just refresh exiting files on project
Hi @leefranke - This is behaving as designed. We only pull existing content, not new files. If you want to pull new files you should perform a retrieve using a package.xml that has either all apex classes or the specific classes you want to retrieve.
The file I'm attempting to pull exists. I created it via the web.
My package.xml has all the ApexClasses.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>*</members> <name>ApexClass</name> </types> <types> <members>*</members> <name>ApexComponent</name> </types> <types> <members>*</members> <name>ApexPage</name> </types> <types> <members>*</members> <name>ApexTestSuite</name> </types> <types> <members>*</members> <name>ApexTrigger</name> </types> <types> <members>*</members> <name>AuraDefinitionBundle</name> </types> <types> <members>*</members> <name>LightningComponentBundle</name> </types> <types> <members>*</members> <name>StaticResource</name> </types> <version>47.0</version> </Package>
Right clicking on the classes subfolder and 'SFDX: Retrieve Source from Org' does not add the existing class.
Or are you saying that once the initial authorize and retrieve is done those are all the files I have to work with? If any new files come into existence after that I have to do the entire process over again?
Hi @leefranke - This is behaving as designed. We only pull existing content, not new files. If you want to pull new files you should perform a retrieve using a package.xml that has either all apex classes or the specific classes you want to retrieve.
It doesn't make sense, unless it have to happen only in Trailhead (or Dev) orgs, because in the Orgs of the company that I work it works normally.
@smaddox-sf This is not working as you described and as @ElsonPaim said, this works in my sandbox and production org, but for some reason it doesn't work on Trailhead orgs. Here's what I did:
- Created trailhead playground and installed a package
- VSC Code > Create project from manifest
- Authorized the org
- Right click on the package.xml which specifies the wildcard to pull all apex classes, and clicked "Retrieve from manifest"
Nothing was retrieved.
If I follow these steps in a prod or sandbox org, it works.
Hi I know that you all have a lot on the roadmap, but I am just adding my name to the list here. I am running into the same issues as everyone else. Works in paid orgs, but not personal dev envs. 🤔.
Something strange: all Apex classes in my org show in the results
array in the ApexClass.json
file.
Hi all, I'll be seeing if I can get to the root issue everyone is having. This is what I've done successfully so far:
- Create a new project with manifest
- Authorize a brand new trailhead org
- Create a new apex class in the trailhead org
- Used the org browser to successfully retrieve the new class
- Used the default manifest with the "create project" command to successfully retrieve the new class
My CLI version: sfdx-cli/7.63.0-c897e8bb1a darwin-x64 node-v10.20.1 My Extension version: 48.21.0
For folks that are trying to retrieve classes that are part of a package, would someone mind elaborating on the kind of package the classes are a part of? @leefranke in your case you're creating a brand new apex class like I did and you shouldn't have to go through another setup process. Have you tried using the org browser sidebar to do the initial retrieve of your new class?
To add additional clarification for anyone trying this, right clicking on the classes folder in your local project and selecting "Retrieve Source from Org" will not retrieve new classes - it retrieves updated versions of the classes already in your local project under that folder. That was how it was designed but we acknowledge how that might be confusing. If you open the org browser (cloud icon in the vscode toolbar) you can click on the cloud icon next to "Apex Classes" to retrieve all the classes in your org, or retrieve individual classes by clicking the button next to their names if you do not want to use a manifest.
Hi @brpowell glad to see this case got reopened! The 5 steps that you did so far work for me as well. I am able to retrieve all classes that I or someone inside my org has created in vscode or the dev console.
I am running into issues only on APEX that is imported from a package.
-
When working on the LWC trailhead superbadge you have to download package 04t6g000008SZzHAAW (this package contains apex classes)
-
I was able to install the package as I normally without errors.
-
I am able to view and modify the apex classes in the dev console
-
I am unable to view/modify/download the apex classes in vscode
Sorry for the image sizing, for some reason I can not get them to be smaller, but I wanted to show you what I am working with. My CLI Version: sfdx-cli/7.61.0 darwin-x64 node-v14.4.0
Thanks!
@handlerda exactly what I was looking for thank you! The issue is that the org browser loads the components based on whether they are editable or not and it gets this information from the metadata api. In Winter 20' the metadata api added values to specify if a component is part of an unlocked package so we can update the org browser to check those values. We'll publish a fix for that.
Hi guys, I've got the same issue..
- Create new Trailhead.
- Install the package.
- Create new project with manifest.
- Retrieve Source from Org.
Nothing happens.. Even in the Org Browser it gives nothing.. Does anyone have any idea what is going on?
Hi @justKev93 - The org browser fix is being released this week (likely tomorrow) so you should be able to see the components in the package once that is out. Are you having issues trying to retrieve another way?
Hi @brpowell, I have also tried using the manifest/package.xml with the defined metadata types that are retrieving nothing. I am not really sure how the Org Browser works. I am basically trying to fulfil the "What do I need to know about the unlocked pacakage" section of this help link to be used for the Lightning Web Components Specialist Superbadge.. So far it has been rather unhelpful.
@justKev93 When the org browser fix goes out tomorrow that'll be an easy way to retrieve components without a manifest. You can read more about it in the user guide here. In the meantime can you share the contents of the manifest you're using? And is this how you're trying to retrieve with it?

@brpowell, that is correct. I created a standard project with a manifest, so this is the default one. The manifest is below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>*</members> <name>ApexClass</name> </types> <types> <members>*</members> <name>ApexComponent</name> </types> <types> <members>*</members> <name>ApexPage</name> </types> <types> <members>*</members> <name>ApexTestSuite</name> </types> <types> <members>*</members> <name>ApexTrigger</name> </types> <types> <members>*</members> <name>AuraDefinitionBundle</name> </types> <types> <members>*</members> <name>LightningComponentBundle</name> </types> <types> <members>*</members> <name>StaticResource</name> </types> <version>49.0</version> </Package>
The fix for retrieving unlocked package metadata through the Org Browser was released as part of version 48.24.0.
The only other question left is on retrieving unlocked package metadata using the package.xml. When you work with packaged metadata, regardless of the type of package, you'll need to explicitly add the name of the file/metadata to the package.xml. The *
will not cover those pieces of metadata.
If my unlocked package is installed in my org and I want to retrieve an Apex Class from it my package.xml will look like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>ExternalNlpDocumentEmotion</members>
<name>ApexClass</name>
</types>
<version>49.0</version>
</Package>
I'm closing this now since the last question has been answered, thanks for the feedback.
I found this solution, It create a new folder with all the pack resources.
sfdx force:source:retrieve -n LWCPackage
Hello! It's 2021 and I am still having this issue. Is really no way to just pull all the source code in an org locally without having to specify each file you want regardless of whether it's an unlocked package or not? I want them all.
Hi @CoderMeow thanks for sharing the feedback! To clarify, the behavior you're looking for is the ability to retrieve source in your org from an unlocked or unmanaged package?
Had the same issue this morning, I solved it by:
- right click on manifest/package.xml -> SFDX: Retrieve source in manifest from org
- wait for process to finish: output should list all missing metadata present in org
- right click on force-app/main/default (or wherever your sfdx project resides) -> SFDX: Retrieve source from org
This will pull all metadata present in the org.
Having the same issue, When I am trying to complete LWC superbadge. VS code working for other sandbox or personal org but when I am using playground org then retrieve not working.
+1 I'm stuck on this too. My error is:
\force-app\main\default\classes\OneOfMyTriggers.cls-meta.xml: Expected source files for type 'ApexClass'
This used to work but just won't anymore. Any other ideas/tips on this? I've tried updating VS Code, SFDX CLI but nothing is working. I've also tried right clicking on package.xml among other things - but every "Retrieve Source from Org" fails w/the above error.
@cemerson your error sounds distinct from the ones others have faced here with code coming from packages. Would you be willing to create a new issue and log the steps to reproduce it so we can discuss your issue specifically? Thanks!
If anyone still faces this issue, this worked for me:
- You create a sub folder in manifest, I think you can call it whatever you want,
- create a new package.xml in that sub folder,
- paste the content of the original package.xml
- execute "Retrieve Source from Org"
I called the sub folder classes because I wanted to try it out with apex classes only initially. After the apex classes were retrieved I added the apex component types to the package.xml and this worked, too. The pulled files were added to the correct dir (force-app\main\default\components...)
Hi @bk107, it didnt help me, I still get the error :(
Update: Turned out that the error "Expected source files for type 'ApexClass'" was referencing a wrong class - it was a class that was deleted but meta-xml file was still there, so I deleted the xml file and it worked :)
I got same, I hit "Retrive Source from Org" and not get all , (defult package.xml create by vscode configure for get all classes), also I got to "org brower" same thing, no got all classes.
Hi @cvizzarri can you tell me a bit more about your current configuration? What type of org are you authorized into? And to confirm, there are existing classes in your org that you're trying to retrieve?
Here's how I "fixed" this:
No amount of package.xml magic will make it update those Apex classes, or LWC Components, period, and to be honest, I blame SFDC for being so 'generic' in trying to leave one in the dusk to figure things out without any context.
Specifically for the LWC Superbadge Exercise, the current trailhead 'instructions' ask you to install a package, that package contains all the metadata to be able to work properly in the challenges ahead, what they don't tell you is that you won't be able to use VSCode to edit your LWC/Classes (I am too frustrated to even think of a reason they would do that.)
Download the package manually: (Anywhere in your filesystem, it does not matter):
sfdx force:source:retrieve -n LWCPackage
It will create a folder called "LWCPackage", in it there will be all the files you need. just copy the folder structure to your VSCode project (previously created of course, in my case I did this (Linux):
julio@tal-shiar:Salesforce/LWCSpecialist $ cp -R ./LWCPackage/main/default/* ./force-app/main/default
Voilá, Al the components are ready to be worked on now, you can edit them in VSCode, and perform normal 'Deploy Source to Org.' and so on.
I managed to resolve this with the help of ChatWingman, an AI language model developed by OSF Digital and Teia Labs, powered by OpenAI. "If you are unable to retrieve a class that was installed by a package, it’s possible that the package has a restriction on retrieving its components. In this case, you may need to contact the package provider to see if they can provide you with the source code for the class.
Alternatively, you can try using the Salesforce CLI to retrieve the class. Here’s how you can do it:
Open a command prompt or terminal window. Navigate to the directory where you want to store the retrieved source code. Run the following command: sfdx force:source:retrieve -m ApexClass:nameOfTheClass" where nameOfTheClass should be replaced with name of the class you want to retrieve
Hi @JulioFS & @CristianVirlan - thanks for sharing how you resolved your issues! Could you tell me a bit more about your project's configuration? What type of org are you authorized into? And to confirm, are there existing classes in your org that you're trying to retrieve?
Hi all,
I also encountered this error Expected source files for type 'ApexClass'
All I did is remove the file makes this error happens. Eg: \force-app\main\default\classes\RandomClass.cls-meta.xml: Expected source files for type 'ApexClass'
-> I remove RandomClass.cls-meta.xml
from the folder, just from the folder and then you can start to pull any component again.