@suman-kundu-wd/plugin-apex-enterprise-scaffold
v0.0.8
Published
This plugin helps to scaffold the apex enterprise pattern for an object with minimal structure of domain, selector, service classes.
Downloads
42
Maintainers
Readme
Salesforce Apex Enterprise Pattern Generator
Building apex trigger on SObject following FFLib enterprise pattern needs couple of classes like domain, selector, service, trigger and few interfaces. This plugin helps to scaffold those classes for an object with minimal code (without any logical part). When we have many objects' triggers to follow the enterprise pattern, it becomes a overhead to create the same structure for every object, and this plugin helps make that process efficient.
Install
$ sf plugins install @suman-kundu-wd/[email protected]
Command Syntax
sf apex-enterprise generate -o <value> -p <value> [--json] [-s y|n] [-e <value>] [-i <value>] [-t <value>] [-w <value>] [-f] [--json]
Flags
| Flag Name | Short Char | Required? | Details | | -------------------- | ---------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --object | -o | Yes | Please provide the object API name for which it will create the enterprise pattern structure. | | --plural | -p | Yes | Please provide the object plural form name which will be used in class’s naming format. Please don't use any space for multi-word name, instead use camel case. | | --save | -s | No | By default, it deploys the generated classes to org. To avoid deploying directly, you may choose 'n'. Valid options 'y' and 'n'. | | --api-version | -i | No | Please provide API Version like 57.0. Default takes the current version. | | --exclude | -e | No | If a user wants to skip component(s) from the structure, he/she may choose to use the component type under the exclude flag. Valid options 'trigger', 'service', 'implementation', 'selector', 'domain' & 'object'. If choosing multiple, use comma ',' as separator and don't use any space in between. | | --team-name | -t | No | If class naming convention should maintain team name in prefix/suffix, please provide team name here. Don't add underscore ('_') here. | | --team-name-position | -w | No | If class naming convention should maintain team name in prefix/suffix, please provide team name position here. Valid values are prefix and suffix. | | --overwrite | -f | No | When generated class or trigger name is already present in project drive, by default system doesn't overwrite. But if we choose overwrite option it will overwrite the existing content. | | --code-path | | No | If the default code content needs to be changed, prepare code md file downloading the original, and then pass the path of the file in this flag. Please don't change the key names in the md file. | | --json | | No | Standard SFDX flag to get response in JSON format. | | --help | -h | No | Standard SFDX flag to get the command details. |
Examples
- Suppose we have a fresh new sobject or an existing sobject but doesn’t yet have any trigger, and we want to create a trigger following the enterprise pattern.:
$ sf apex-enterprise generate -o Custom_Price__c -p CustomPrices -i 55.0
- Suppose we have an existing sobject which has a trigger already with non-enterprise structure, and we want to create a trigger following the enterprise pattern.:
$ sf apex-enterprise generate -o Opportunity -p Opportunities -s n -e trigger
- Suppose we have a fresh new sobject and we want to create a trigger following the enterprise pattern. As there are multiple teams working on same Salesforce org, team uses team's naming convention for easy identification.:
$ sf apex-enterprise generate -o Custom_Price__c -p CustomPrices -t CLOSE -w suffix
- Suppose we have an existing sobject having trigger and classes with old pattern. Now while executing this command, it may generate the same file name. By default, it doesn't overwrite, instead fails. To forcefully overwrite use below command with overwrite (-f) flag.:
$ sf apex-enterprise generate -o Custom_Price__c -p CustomPrices -f
- Suppose the provided default codes do not match your expectation completely and need some change, then download the code.components.md file, update the content but don't change the keys and then provide the file path in the code-path flag.:
$ sf apex-enterprise generate -o Custom_Price__c -p CustomPrices --code-path /Users/suman.kundu/Desktop/code.components.md
Components Table
| Component Name | Type | Purpose | | -------------------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [Plural Input].trigger | Trigger | It calls the FFLIB SObject Domain class to initiate the trigger process. | | [Plural Input]TriggerHandler.cls | Apex Class | This is the domain class handles trigger events, validation, defaulting etc. | | [Plural Input].cls | Apex Class | This class helps to define methods or actions specific to the SObject. | | I[Plural Input].cls | Apex Class (Interface) | This is an interface, helps to maintain an object's methods or actions contract. | | [Plural Input]ServiceImpl.cls | Apex Class | This class holds all the core services provided on this object and their implementation logic. | | I[Plural Input]Service.cls | Apex Class (Interface) | This is an interface, helps to maintain an object's service implementation contract. | | [Plural Input]Service.cls | Apex Class | It can be considered as an API of object’s provided services to the external components like controller, other object services etc. | | [Plural Input]Selector.cls | Apex Class | This class maintains all the different queries of this object, so that it becomes better maintainable (as it’s centralized), makes it efficient (as in single transaction we can control to not get invoked multiple times). | | I[Plural Input]Selector.cls | Apex Class (Interface) | This is an interface, helps to maintain an object's selector methods’ contract. |
- [Plural Input]: This is the same value that is provided in the plural (-p) flag in command.
- In case of prefix team name provided, component name starts with '[Team-Name Input]_' like: [Team-Name Input]_[ComponentName].[extention].
- In case of suffix team name provided, component name ends with '_[Team-Name Input]' like: [ComponentName]_[Team-Name Input].[extention]
Prerequisites
- SFDX must be installed in the developer’s laptop with updated version.
- FFLIB Apex Enterprise Library must be installed in the present organization before executing or deploying these generated enterprise classes.
- Node is installed in the developer’s laptop.