function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marketing Marketing 27Marketing Marketing 27 

SFDX How to Import only a few specific apex classes from your connected org?

Just started using VS code and SFDX for development work and am trying to use it to update classes I had previously written in the developer console.

My question is, how can I import just a few select classes into the VS code project without pulling all of them? I know that you can right click on Package XML and click Retrieve Source in Manifest from Org, but that brings in everyting, and I don't want that.

Is there a terminal command that can solve for this?

Thanks
Best Answer chosen by Marketing Marketing 27
VinayVinay (Salesforce Developers) 
You would need to update your package.xml file with specific apex class names which you want to retrieve using vs code.
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Class1</members>
        <members>Class2</members>
        <name>ApexClass</name>
    </types>
    <version>54.0</version>
</Package>

Please mark as Best Answer if above information was helpful.

Thanks,

All Answers

VinayVinay (Salesforce Developers) 
You would need to update your package.xml file with specific apex class names which you want to retrieve using vs code.
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Class1</members>
        <members>Class2</members>
        <name>ApexClass</name>
    </types>
    <version>54.0</version>
</Package>

Please mark as Best Answer if above information was helpful.

Thanks,
This was selected as the best answer
Marketing Marketing 27Marketing Marketing 27
Ahh, so the class names come before the <name>ApexClass</name> element?

One more quetion: If I delete the other class files it imported from the project folder and then run sfdx force:source:push, will that delete those classes from the connected org or will it only delete them from VS code?
VinayVinay (Salesforce Developers) 
Yes '<name>ApexClass</name>' comes before and no it wont delete any other class if you have not included them in package.xml unless you run destructive changes in vs code.

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_deleting_files.htm

Thanks,
Marketing Marketing 27Marketing Marketing 27
Thank you so much Vinay! Much appreciated.