Alternative to SFDX: Retrieve Source in Manifest from Org
In majority cases, while creating project in VS Code, one follows the 3 steps; create project using manifest, authorize org and retrieve source in manifest from org. As manifest is the file, that might change from org to org, its a general practice to create a manifest or package.xml file with commonly retrieved metadata items like apex classes, lightning web components and so on. However, as the package.xml file becomes bigger in size (not specifically to certain number of lines) the SFDX command, retrieve source in manifest from org might or might not work (without any error). If the command is explicitly ran from terminal, it shows internal error with error code. Common workarounds like, restarting VS Code or updating Salesforce CLI would not help in this situation. This becomes a bottle neck.
Fortunately there are ways to retrieve the metadata, lets see the options we have.
Option 1: Reduce the number of lines in package.xml
This is trial and error method. To reach to a point where the SFDX command retrieve source in manifest from org would work either by gradually increasing or decreasing the lines (metadata elements) in package.xml
Option 2: Use org browser in VS Code
VS Code provides an option of org browser to see and retrieve metadata of an org. However, the elements needs to be retrieved one by one.
Option 3: Configure a task to retrieve metadata
This is so far the reliable and feasible way to retrieve all the metadata components you wish to retrieve. And it works every time. To use this option, one need to follow below steps.
Configure Task in VS Code
Step 1: Create a task.json file
Press Ctrl + shift + P > Tasks: Configure Task > Create task.json file from template > Other
This will create the task.json file under .vscode folder
Step 2: Create commands for metadata elements you wish to retrieve
Use force:source:retrieve command specifically for metadata element e.g. command to retrieve apex classes would be
sfdx force:source:retrieve -m ApexClass
Configure this as command in task.json. Like package.xml, create command for all items to be retrieved. This is as good as creating creating package.xml one time and use it for all projects setup.
Step 3: Add the command dependency
Update any one command to introduce dependency on the other commands (Refer the command by their label specified). Specify the dependsOrder as parallel so that commands are executed parallelly.
Execute the configured task in VS Code
To run this command press Ctrl + Shift + B as we have specified group as build.
If you have only one task configured which has dependencies specified on all other commands, VS Code will start execution of commands parallelly. However, if you have multiple tasks or command configured you will have to choose which one to execute.
task.json file have to be added in every project like we used to update the package.xml
This task will always work irrespective of number of metadata elements retrieved.
Thanks for your time to go through the post, hope it helps!