-
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.
* Added test class for parent picklist * Added ability to select parent field * Standardised comments * Added parent record property * Add parent record property * Added support for Parent Field Property * Custom rule for parameters * Refresh types when Parent Field changes * Prettier updates * Made inaccessible field clearer * Added code coverage * Added dot notations for test coverage * prettier updates Co-authored-by: David Norris <[email protected]>
- Loading branch information
1 parent
fe2056c
commit 2e0f04b
Showing
10 changed files
with
347 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @description Supporting Apex to get all supported parent object fields for the Timeline Lightning Web Component | ||
* This allows the component to plot for different fields and contexts (e.g. shows the Contact timeline on a Case) | ||
*/ | ||
global with sharing class TimelineParentPicklist extends VisualEditor.DynamicPickList { //NOPMD | ||
VisualEditor.DesignTimePageContext context; | ||
|
||
/** | ||
* @description Apex class constructot passing context from the Lightning Web Component | ||
* @param context The DesignTimePageContext to get Entity Name and Page Type | ||
*/ | ||
global TimelineParentPicklist(VisualEditor.DesignTimePageContext context) { | ||
this.context = context; | ||
} | ||
|
||
global override VisualEditor.DataRow getDefaultValue() { | ||
//objectLabel = System.Label.Timeline_Label_Files; | ||
String objectLabel = ((SObject) (Type.forName('Schema.' + String.valueOf(this.context.entityName)) | ||
.newInstance())) | ||
.getSObjectType() | ||
.getDescribe() | ||
.getLabel(); | ||
VisualEditor.DataRow defaultValue = new VisualEditor.DataRow( | ||
'Use This ' + objectLabel, | ||
'Default_Picklist_Value' | ||
); | ||
return defaultValue; | ||
} | ||
|
||
global override VisualEditor.DynamicPickListRows getValues() { | ||
VisualEditor.DynamicPickListRows myValues = new VisualEditor.DynamicPickListRows(); | ||
myValues.addRow(getDefaultValue()); | ||
|
||
Schema.DescribeSObjectResult describeSobjects = ((SObject) (Type.forName('Schema.' + this.context.entityName) | ||
.newInstance())) | ||
.getSObjectType() | ||
.getDescribe(); | ||
|
||
Map<String, Schema.SObjectField> myFields = describeSobjects.fields.getMap(); | ||
|
||
for (String field : myFields.keySet()) { | ||
Schema.DescribeFieldResult currentField = myFields.get(field).getDescribe(); | ||
|
||
if ( | ||
currentField.isAccessible() && | ||
currentField.isNamePointing() == false && | ||
currentField.getLabel() != 'Master Record ID' && | ||
(String.valueOf(currentField.getReferenceTo()) == '(Lead)' || | ||
String.valueOf(currentField.getReferenceTo()) == '(Contact)' || | ||
String.valueOf(currentField.getReferenceTo()) == '(Account)' || | ||
String.valueOf(currentField.getReferenceTo()) == '(Opportunity)' || | ||
String.valueOf(currentField.getReferenceTo()) == '(Case)') | ||
) { | ||
myValues.addRow(new VisualEditor.DataRow(currentField.getLabel(), field)); | ||
} | ||
} | ||
return myValues; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/TimelineParentPicklist.cls-meta.xml
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>49.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
39 changes: 39 additions & 0 deletions
39
force-app/main/default/classes/TimelineParentPicklist_Test.cls
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,39 @@ | ||
/** | ||
* @description Supporting test class to check the Timeline picklist | ||
* 1 - Does the picklist return the correct default values | ||
* 2 - Does the picklist return at least 1 value for the Contact standard object | ||
*/ | ||
@isTest(seeAllData=false) | ||
private with sharing class TimelineParentPicklist_Test { | ||
@isTest | ||
static void testTimelinePicklistDefaultValue() { | ||
VisualEditor.DesignTimePageContext context = new VisualEditor.DesignTimePageContext(); | ||
context.entityName = 'Contact'; | ||
|
||
TimelineParentPicklist timeline = new TimelineParentPicklist(context); | ||
|
||
Test.startTest(); | ||
VisualEditor.DataRow defaultValue = timeline.getDefaultValue(); | ||
Test.stopTest(); | ||
|
||
System.assertEquals( | ||
'Use This Contact', | ||
defaultValue.getLabel(), | ||
'Timeline Parent Picklist default value incorrect' | ||
); | ||
} | ||
|
||
@isTest | ||
static void testTimelinePicklistValues() { | ||
VisualEditor.DesignTimePageContext context = new VisualEditor.DesignTimePageContext(); | ||
context.entityName = 'Contact'; | ||
|
||
TimelineParentPicklist timeline = new TimelineParentPicklist(context); | ||
|
||
Test.startTest(); | ||
VisualEditor.DynamicPickListRows picklistValues = timeline.getValues(); | ||
Test.stopTest(); | ||
|
||
System.assert(picklistValues.size() > 0, 'No parent picklist values found for Contact'); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/TimelineParentPicklist_Test.cls-meta.xml
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>49.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
Oops, something went wrong.