Miscellaneous - cdelfattore/apex-enterprise-patterns GitHub Wiki

Introduction

Topics not necessarily related to Apex Enterprise Design Patterns specifically, but wanted to mention since they are important when working on any project.

Indentation and brackets

I believe it is important to consistently use the same style of formatting in apex classes. I prefer the Allman style for brackets and indentation, see below. Although if a majority of the team prefers another style then that can be adopted. The goal is to consistently use the same style so the code looks uniform.

Allman

while (x == y)
{
    something();
    something_else();
}

final_thing();

Additional Styles

Commenting Style

I prefer using this package to assist with commenting Apex classes and methods. It is similar to a Javadoc format. Feature I like with this package is the comment will add the parameters and return type automatically after typing /*. Then running the the ApexDox: Run command will generate the documentation from the class and method level comments.

Example

/**
* @description Select by the LastModifiedId, OrderByLastModifiedDate Desc, with related Contacts.
* @param userIds 
* @param recordAmount 
* @return  `List<Account>`
*/
public List<Account> selectByLastModifiedIdWithContacts(Set<Id> userIds, Integer recordAmount)
{
	fflib_QueryFactory accountsQueryFactory = newQueryFactory();

	fflib_QueryFactory contactsQueryFactory = new ContactsSelector()
                .addQueryFactorySubselect(accountsQueryFactory);

	return (List<Account>) Database.query(
		accountsQueryFactory
			.setCondition('LastModifiedById IN :userIds')
			.setOrdering('LastModifiedDate', fflib_QueryFactory.SortOrder.DESCENDING)
			.setLimit(recordAmount)
			.toSOQL()
	);
}

Additional information can be found [here](ApexDox VS Code)

⚠️ **GitHub.com Fallback** ⚠️