forked from dschach/MavensMate-Templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from jondavis9898/master
Add templates for fflib_DomainObjectBuilder and update Domain Class
- Loading branch information
Showing
4 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* See https://github.com/financialforcedev/fflib-apex-common for more info | ||
* | ||
* Install library via | ||
* https://githubsfdeploy.herokuapp.com/app/githubdeploy/financialforcedev/fflib-apex-common | ||
*/ | ||
|
||
/** | ||
* Base class for Domain specific builders implementing the Test Data Builder pattern as described | ||
* by Nate Pryce (http://www.natpryce.com/) and Object Mother Pattern (http://www.c2.com/cgi/wiki?ObjectMother) | ||
* | ||
* For more guidelines and details see | ||
* https://github.com/financialforcedev/fflib-apex-common | ||
* https://github.com/financialforcedev/fflib-apex-common-samplecode | ||
**/ | ||
public abstract class {{ api_name }} extends fflib_DomainObjectBuilder | ||
{ | ||
/** | ||
* @description Constructs the Builder class with the specified SObjectType | ||
* | ||
* @param type The SObject type that the builder will build | ||
**/ | ||
protected {{ api_name }}(SObjectType type) | ||
{ | ||
super(type); | ||
} | ||
|
||
/** | ||
* @description Copy Constructor that constructs the Builder class based on the builder specified | ||
* | ||
* @param copyFrom The builder to copy/clone this instance from | ||
**/ | ||
protected {{ api_name }}({{ api_name }} copyFrom) | ||
{ | ||
super(copyFrom); | ||
} | ||
|
||
/** | ||
* @description Helper method to obtain the default Unit Of Work for use with persist methods | ||
**/ | ||
protected virtual fflib_ISObjectUnitOfWork createUnitOfWork() | ||
{ | ||
/** | ||
* @todo If using Application class concept from the Apex Enterprise Patterns, change the below to | ||
* return from Application.UnitOfWork.newInstance(). | ||
* If not using the Application class concept, add the default SObjectTypes that should be | ||
* passed to Unit Of work construction. This method will be called by derived builders | ||
* during persist() method call. | ||
*/ | ||
|
||
//return Application.UnitOfWork.newInstance(); | ||
return new fflib_SObjectUnitOfWork(new List<SObjectType> {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* See https://github.com/financialforcedev/fflib-apex-common for more info | ||
* | ||
* Install library via | ||
* https://githubsfdeploy.herokuapp.com/app/githubdeploy/financialforcedev/fflib-apex-common | ||
*/ | ||
|
||
/** | ||
* Domain specific class implementing the Test Data Builder pattern as described by Nate Pryce | ||
* (http://www.natpryce.com/) and Object Mother Pattern (http://www.c2.com/cgi/wiki?ObjectMother) | ||
* | ||
* For more guidelines and details see | ||
* https://github.com/financialforcedev/fflib-apex-common | ||
* https://github.com/financialforcedev/fflib-apex-common-samplecode | ||
**/ | ||
public class {{ api_name }} extends {{ base_name }} | ||
{ | ||
/** | ||
* @description Default constructor | ||
**/ | ||
private {{ api_name }}() | ||
{ | ||
super({{ object_name }}.SObjectType); | ||
} | ||
|
||
/** | ||
* @description Copy Constructor that constructs the Builder class based on the builder specified | ||
* | ||
* @param copyFrom The builder to copy/clone this instance from | ||
**/ | ||
private {{ api_name }}({{ api_name }} copyFrom) | ||
{ | ||
super(copyFrom); | ||
} | ||
|
||
/** | ||
* @description Creates an existing SObject without issuing DML | ||
* | ||
* @remarks Wrapper method to base class to allow for casting of specific SObjectType | ||
**/ | ||
public {{ object_name }} build() | ||
{ | ||
return ({{ object_name }})build(false); | ||
} | ||
|
||
/** | ||
* @description Creates an New SObject (No Id) without issuing DML | ||
* | ||
* @remarks Wrapper method to base class to allow for casting of specific SObjectType | ||
**/ | ||
public {{ object_name }} buildNew() | ||
{ | ||
return ({{ object_name }})build(true); | ||
} | ||
|
||
/** | ||
* @description Persists builder and its related data through Unit Of Work | ||
* | ||
* @remarks Wrapper method to base class to allow for casting of specific SObjectType | ||
**/ | ||
public {{ object_name }} persist(fflib_ISObjectUnitOfWork uow) | ||
{ | ||
return ({{ object_name }})persistBuilder(uow); | ||
} | ||
|
||
/** | ||
* @description Persists builder and its related data using default unit of work | ||
* | ||
* @remarks Wrapper method to base class to allow for casting of specific SObjectType | ||
**/ | ||
public {{ object_name }} persist() | ||
{ | ||
return persist(createUnitOfWork()); | ||
} | ||
|
||
/** | ||
* @description Registers instance for persistance via persistBuilders | ||
* | ||
* @remarks Wrapper method to base class to allow for casting of specific SObjectType | ||
**/ | ||
public {{ api_name }} register() | ||
{ | ||
return ({{ api_name }})registerBuilder(); | ||
} | ||
|
||
/** | ||
* @description Returns Contact SObject associated to this builder | ||
* | ||
* @remarks Wrapper method to base class to allow for casting of specific SObjectType | ||
**/ | ||
public {{ object_name }} Record | ||
{ | ||
get { return ({{ object_name }})getRecord(); } | ||
private set; | ||
} | ||
|
||
/** | ||
* @description Returns a Clone of this instance | ||
**/ | ||
public {{ api_name }} but() | ||
{ | ||
return new {{ api_name }}(this); | ||
} | ||
|
||
/** | ||
* @description Object Mother method for an empty {{ api_name }} instance | ||
**/ | ||
public static {{ api_name }} {{ mother_name }}() | ||
{ | ||
return new {{ api_name }}(); | ||
} | ||
|
||
/* | ||
* @todo Add additional Object Mother methods for commonly used values | ||
* | ||
* For more examples see https://github.com/financialforcedev/fflib-apex-common-samplecode | ||
* | ||
* | ||
public static {{ api_name }} {{ mother_name }}WithRequiredFields() | ||
{ | ||
return {{ mother_name }}() | ||
.withName('Test Name') | ||
.withType('My Type'); | ||
} | ||
*/ | ||
|
||
/* | ||
* @todo Add methods to set field values | ||
* | ||
* For more examples see https://github.com/financialforcedev/fflib-apex-common-samplecode | ||
* | ||
public {{ api_name }} withName(String value) | ||
{ | ||
set({{ object_name }}.Name, value); | ||
return this; | ||
} | ||
public {{ api_name }} withAccount(Account_t value) | ||
{ | ||
setParent({{ object_name }}.AccountId, value); | ||
return this; | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters