0

How would I set up my build file so I can split up apex classes into sibling folders inside src?

Currently, I got deployRoot = "src" set up in the build file, and I assumed that ANT can recognize all .cls files, wherever they reside (as long as they are in the src directory), but apparently it only recognizes files inside the classes folder. How can I make ANT understand that there is an additional folder with apex classes inside the helperclasses folder?

src
├── classes
│   ├── apexclass1.cls
│   └── apexclass2.cls
├── helperclasses
│   ├── testfactorydefault1class.cls
│   └── testfactorydefaul2class.cls

1 Answer 1

2

This isn't supported in Ant. You're looking for sfdx. If you want to do this in Ant, you can provide multiple packages.

C:\WORKSPACE\DEMO\SRC
├───package1
│   │   package.xml
│   │
│   └───classes
│           Class1.cls
│           Class1.cls-meta.xml
│
└───package2
    │   package.xml
    │
    └───classes
            Class2.cls
            Class2.cls-meta.xml

If you do this, make sure you don't use the "single package" flag.

The package.xml file is a full manifest file for all the content of that folder. Given the above example, the files would be:

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

And

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

For each respective package folder.

11
  • Thanks - what goes in each package.xml file in pkg1 and pkg2? Should there be one package.xml in each subdirectory as well as in the parent directory? Also, not exactly sure where ant/sfdx overlaps. Does SFDX replace a tool like Travis, or can travis be set up to deploy with sfdx as well?
    – erikvm
    Apr 21, 2022 at 13:50
  • @erikvm each package.xml contains a full manifest file that lists every component contained in the package. You should already have one of these to start from.
    – sfdcfox
    Apr 21, 2022 at 14:34
  • @erikvm I was previously mobile, now that I'm home, I updated the answer so it's hopefully clearer.
    – sfdcfox
    Apr 21, 2022 at 14:54
  • @erikvm Also you could convert source format to metadata and deploy using Metadata API (Ant) Apr 21, 2022 at 15:37
  • Thanks for the detailed answer, @sfdcfox. What about the package.xml file that sits in the parent directory of "src" - should that "parent" package xml still exist? And if so, should it have <types>....</types> with everything but apex classes from the subfolders? The "parent" package.xml I'm referring to is the one automatically generated that provides this: <types> <members>*</members> <name>ApexClass</name> </types> <types> <members>*</members> <name>ApexComponent</name> </types> etc
    – erikvm
    Apr 21, 2022 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .