-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Transfrom to support functional mapping
- Loading branch information
Showing
8 changed files
with
81 additions
and
3 deletions.
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
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,17 @@ | ||
public class RecordTransform implements SObjectToSObjectFunction { | ||
private SObject prototype; | ||
private Map<String, Object> populatedFieldsMap; | ||
|
||
public SObject apply(SObject record) { | ||
|
||
for (String field : populatedFieldsMap.keySet()) { | ||
record.put(field, prototype.get(field)); | ||
} | ||
return record; | ||
} | ||
|
||
public RecordTransform(sObject prototype) { | ||
this.prototype = prototype; | ||
this.populatedFieldsMap = prototype.getPopulatedFieldsAsMap(); | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>44.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
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,19 @@ | ||
@IsTest | ||
public class RecordTransformTest { | ||
@IsTest | ||
public static void definedFieldsAreUsed() { | ||
Opportunity opp = new Opportunity(); | ||
RecordTransform t = Transform.record(new Opportunity(Amount = 1000, Name = 'Test')); | ||
t.apply(opp); | ||
System.assertEquals(1000, opp.Amount); | ||
System.assertEquals('Test', opp.Name); | ||
} | ||
|
||
@IsTest | ||
public static void fieldsAreOverwritten() { | ||
Opportunity opp = new Opportunity(Amount = 1000); | ||
RecordTransform t = Transform.record(new Opportunity(Amount = 2000)); | ||
t.apply(opp); | ||
System.assertEquals(2000, opp.Amount); | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>44.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
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,5 @@ | ||
public with sharing class Transform { | ||
public static RecordTransform record(SObject record) { | ||
return new RecordTransform(record); | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>44.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |