forked from apex-enterprise-patterns/fflib-apex-common
-
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.
Started work on a generic LWC that allows an LWC to be included in a …
…Tab Page
- Loading branch information
1 parent
7432b57
commit 9dcd0f6
Showing
6 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
framework/default/ortoo-core/default/classes/utils/DateTimeUtils.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,18 @@ | ||
/** | ||
* Utility class that provides extra capabilities related to DateTime | ||
* | ||
* @group Utils | ||
*/ | ||
public inherited sharing class DateTimeUtils | ||
{ | ||
/** | ||
* Returns the current Epoch Time, in seconds | ||
* | ||
* @return Long The current Epoch Time, in seconds | ||
*/ | ||
public static Long getEpochTime() | ||
{ | ||
Long millisecondsNow = Datetime.now().getTime(); | ||
return millisecondsNow / 1000; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
framework/default/ortoo-core/default/classes/utils/DateTimeUtils.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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
107 changes: 107 additions & 0 deletions
107
...rk/default/ortoo-lwc-list-view-buttons/classes/AbstractRedirectToLwcTabPageController.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,107 @@ | ||
/** | ||
* Base Visualforce Controller extension that provides the required controller methods for building | ||
* a Visualforce page that: | ||
* Can be used on a List Button | ||
* Redirects the screen to a Lightning Tab | ||
* Passes a serialised version of the record Ids | ||
* Includes a timestamp (Epoch time in seconds) for the generation of the URL | ||
* Includes a return URL | ||
*/ | ||
public virtual with sharing class AbstractRedirectToLwcTabPageController { | ||
|
||
protected String tabPageName; | ||
|
||
/** | ||
* States if the controller currently has records assigned to it | ||
*/ | ||
public Boolean hasRecords | ||
{ | ||
get | ||
{ | ||
return recordIds?.size() > 0; | ||
} | ||
} | ||
|
||
/** | ||
* States the URL that the page should return to on completion or cancellation | ||
*/ | ||
public String returnUrl | ||
{ | ||
get | ||
{ | ||
String returnUrl = new ApexPages.Action('{!cancel}').invoke().getUrl(); | ||
// | ||
// There's an issue that means the cancel URL sometimes forgets where it's come from. | ||
// In that situation, it reverts to the SObject's 'home' | ||
// When this happens we want to load the most recently loaded list for the current SObject type instead. | ||
// | ||
if ( returnUrl.endsWith( '/home' ) ) | ||
{ | ||
returnUrl = new ApexPages.Action('{!list}').invoke().getUrl(); | ||
} | ||
return returnUrl; | ||
} | ||
} | ||
|
||
/** | ||
* Is a representation of the current recordIds in a serialised form | ||
*/ | ||
private String serializedRecordIds | ||
{ | ||
get | ||
{ | ||
return JSON.serialize( recordIds ); | ||
} | ||
} | ||
|
||
/** | ||
* The current Epoch Time in seconds, as a String | ||
*/ | ||
private String epochTime | ||
{ | ||
get | ||
{ | ||
return String.valueOf( DateTimeUtils.getEpochTime() ); | ||
} | ||
} | ||
|
||
/** | ||
* The currently recordIds that are currently assigned to this controller | ||
*/ | ||
private List<Id> recordIds; | ||
|
||
/** | ||
* Standard controller extension constructor, utilising the standard set controller. | ||
* Retrieves the currently selected records from the controller. | ||
* | ||
* @param ApexPages.StandardSetController The set controller that contains the context for this controller | ||
*/ | ||
public AbstractRedirectToLwcTabPageController( ApexPages.StandardSetController controller ) | ||
{ | ||
recordIds = new List<Id>(); | ||
List<Sobject> selectedSobjects = controller.getSelected(); | ||
|
||
for( Sobject thisSobject : selectedSobjects ) | ||
{ | ||
recordIds.add( (Id)thisSobject.get( 'Id' ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Controller method that performs the re-direction of the browser page to the specified Tab Page. | ||
* | ||
* Includes parameters for defining the return Url, the Epoch time (for checking the timely usage of the link) | ||
* and the record Ids that are to be processed. | ||
*/ | ||
public PageReference redirectToTabPage() { | ||
|
||
Contract.requires( this.tabPageName != null, 'redirectToTabPage called with a null this.tabPageName. Ensure that the controller extension ('+ObjectUtils.getClassName( this )+') sets "this.tabPageName" in the constructor' ); | ||
|
||
PageReference appPage = new PageReference( '/lightning/n/' + this.tabPageName ); // TODO: may not need the 'lightning' bit... | ||
appPage.getParameters().put( 'c__returnUrl', returnUrl ); | ||
appPage.getParameters().put( 'c__epoch', epochTime ); | ||
appPage.getParameters().put( 'c__recordIds', serializedRecordIds ); | ||
appPage.setRedirect( true ); | ||
return appPage; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...t/ortoo-lwc-list-view-buttons/classes/AbstractRedirectToLwcTabPageController.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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
17 changes: 17 additions & 0 deletions
17
framework/default/ortoo-lwc-list-view-buttons/classes/TimeController.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,17 @@ | ||
/** | ||
* A Lightning Controlller that provides access to the Epoch Time as defined by the | ||
* Salesforce instance's clock | ||
*/ | ||
public with sharing class TimeController { | ||
|
||
/** | ||
* Returns the current Epoch time, in seconds | ||
* | ||
* @return Long The current Epoch Time, in seconds. | ||
*/ | ||
@AuraEnabled | ||
public static Long getEpochTime() | ||
{ | ||
return DateTimeUtils.getEpochTime(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
framework/default/ortoo-lwc-list-view-buttons/classes/TimeController.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>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |