6

By default the Salesforce DX CLI creates a project with folders:

force-ap
-- main
   -- default
      -- aura

And all the examples have files organised by type:

classes
objects
layouts
profiles
etc...

QUESTIONS

  1. Do I need main and default?
  2. Do I need to organise the code, metadata etc as per the examples online, or can I organise it however I like?
5

Do I need main and default?

No, but you may want a similar layout. The top level should have two folders, main and test, where test keeps all of your unit tests, etc. Default is used to store the base org data that all other packages depend on. You might have other packages (recommended) for specific features that you implement in your org.

Do I need to organise the code, metadata etc as per the examples online, or can I organise it however I like?

The files need to be present relative to each other, but the hierarchy is otherwise open to do as you wish. For example, the objects folder is necessary to store metadata about your CustomObject metadata, but it can exist wherever you like, so long as it contains only CustomObject metadata.

Of course, you can ignore it, and just drop everything into the root folder, if you wish. If you're just doing a small project, this is just fine, everything should work as you expect. However, as your code grows, you may find yourself wishing that you'd started with a plan.

For example, we have over 10,000 artifacts in our repo. This was started before DX. In order to start using DX properly, we now have to shuffle around 10,000+ files so we can generate second generation packages. Our last attempt took close to a month, and we ultimately abandoned it until we had the time to do it properly.

So, for playing around with DX, feel free to do whatever you like. Just remember that not following the best practice will likely cause you major problems down the road. Or not. Just consider how big you expect your project to become, and consider the consequences.

Lumping everything into a single spot might also have performance implications, as pushes and pulls may take significant time. There's also still inherent limitations as to how much metadata you can move at once, so smaller is better.

  • Should I create Apex test classes within folder force-ap > test > main > classes ? because if I retrieve source from an Org all apex classes get placed into force-app > main > default > classes – Robs Sep 9 '18 at 9:43
  • @Robs that's how the default path thing works. Once you put stuff in different folders, it should pull correctly. At any rate, it's normally force-app/test/default/classes and force-app/main/default/classes. You need to set up your sfdx-project.json file correct for things to work, too. – sfdcfox Sep 9 '18 at 14:09

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.