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
teena jacobteena jacob 

Group apex classes like packages or namespaces

Hi,
  Is there any way to group apex classes like packages or namespaces.

Thanks.
Best Answer chosen by teena jacob
Khan AnasKhan Anas (Salesforce Developers) 
Hi Teena,

Greetings to you!

Apex classes are stored in the classes folder in the corresponding package directory. You cannot create a package in Salesforce to put your class. Salesforce put all the classes in a default folder. Apex classes doesn’t support nested namespaces or packages like Java to organize code in a clean way.

You can use the naming convention for your Apex Classes i.e.; use some specific keyword when creating classes:
  • Prefixing class names: 
    {prefix}_classname.cls
           eg.: page_AccountTable
                  trgr_AccountDuplicate
 
  • Suffixing class names: 
    classname_{suffix}.cls
           eg.: AccountTable_page
                  AccountDuplicate_trgr


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Teena,

Greetings to you!

Apex classes are stored in the classes folder in the corresponding package directory. You cannot create a package in Salesforce to put your class. Salesforce put all the classes in a default folder. Apex classes doesn’t support nested namespaces or packages like Java to organize code in a clean way.

You can use the naming convention for your Apex Classes i.e.; use some specific keyword when creating classes:
  • Prefixing class names: 
    {prefix}_classname.cls
           eg.: page_AccountTable
                  trgr_AccountDuplicate
 
  • Suffixing class names: 
    classname_{suffix}.cls
           eg.: AccountTable_page
                  AccountDuplicate_trgr


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Felix van Hove 22Felix van Hove 22
Update from 'couple of years later:

Salesforce has introduced the concept of unlocked packages (both with or without namespaces) - check it out (https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_unlocked_pkg_intro.htm). 

More recently it got possible to organize classes in folders under classes/ (and in even more fancy locations). For a decent example look here (https://github.com/trailheadapps/apex-recipes) . (Though this is a purely local thing and doesn't exist on the org itself.)