diff --git a/dlrs/main/classes/RollupController.cls b/dlrs/main/classes/RollupController.cls
index 6a1c9d83..2eebad87 100644
--- a/dlrs/main/classes/RollupController.cls
+++ b/dlrs/main/classes/RollupController.cls
@@ -28,8 +28,8 @@
* Handles the Manage Trigger and Calculate Custom Buttons
**/
public with sharing class RollupController {
-
- public static String API_VERSION = '58.0';
+ @TestVisible
+ private static String FALLBACK_COMPONENT_API_VERSION = '58.0';
public String ZipData { get; set; }
@@ -63,6 +63,9 @@ public with sharing class RollupController {
public Boolean MetadataConnectionError { get; set; }
+ @TestVisible
+ private String componentApiVersion;
+
public RollupController(ApexPages.StandardController standardController) {
// Query Lookup Rollup Summary record
this(
@@ -101,7 +104,7 @@ public with sharing class RollupController {
return '' +
'' +
'' +
- API_VERSION +
+ componentApiVersion +
'' +
'';
else
@@ -135,7 +138,7 @@ public with sharing class RollupController {
'')
: '') +
'' +
- API_VERSION +
+ componentApiVersion +
'' +
'';
}
@@ -170,7 +173,7 @@ public with sharing class RollupController {
'')
: '') +
'' +
- API_VERSION +
+ componentApiVersion +
'' +
'';
}
@@ -183,7 +186,7 @@ public with sharing class RollupController {
return '' +
'' +
'' +
- API_VERSION +
+ componentApiVersion +
'' +
'Active' +
'';
@@ -228,7 +231,7 @@ public with sharing class RollupController {
return '' +
'' +
'' +
- API_VERSION +
+ componentApiVersion +
'' +
'Active' +
'';
@@ -269,7 +272,7 @@ public with sharing class RollupController {
return '' +
'' +
'' +
- API_VERSION +
+ componentApiVersion +
'' +
'Active' +
'';
@@ -316,7 +319,7 @@ public with sharing class RollupController {
return '' +
'' +
'' +
- API_VERSION +
+ componentApiVersion +
'' +
'Active' +
'';
@@ -403,12 +406,12 @@ public with sharing class RollupController {
new ApexPages.Message(
ApexPages.Severity.Error,
deployMessage.fileName +
- ' (Line: ' +
- deployMessage.lineNumber +
- ': Column:' +
- deployMessage.columnNumber +
- ') : ' +
- deployMessage.problem
+ ' (Line: ' +
+ deployMessage.lineNumber +
+ ': Column:' +
+ deployMessage.columnNumber +
+ ') : ' +
+ deployMessage.problem
)
);
// Test errors?
@@ -421,12 +424,12 @@ public with sharing class RollupController {
new ApexPages.Message(
ApexPages.Severity.Error,
testFailure.name +
- '.' +
- testFailure.methodName +
- ' ' +
- testFailure.message +
- ' ' +
- testFailure.stackTrace
+ '.' +
+ testFailure.methodName +
+ ' ' +
+ testFailure.message +
+ ' ' +
+ testFailure.stackTrace
)
);
// Code coverage warnings?
@@ -438,11 +441,11 @@ public with sharing class RollupController {
new ApexPages.Message(
ApexPages.Severity.Warning,
(codeCoverageWarning.namespace != null
- ? codeCoverageWarning.namespace + '.'
- : '') +
- codeCoverageWarning.name +
- ':' +
- codeCoverageWarning.message
+ ? codeCoverageWarning.namespace + '.'
+ : '') +
+ codeCoverageWarning.name +
+ ':' +
+ codeCoverageWarning.message
)
);
@@ -493,6 +496,7 @@ public with sharing class RollupController {
);
return;
}
+ componentApiVersion = getNewestApiVersion();
// Already deployed?
Set triggerNames = new Set{ RollupTriggerName };
@@ -566,8 +570,8 @@ public with sharing class RollupController {
new ApexPages.Message(
ApexPages.Severity.Info,
'Apex Trigger ' +
- RollupParentTriggerTestName +
- ' is installed.'
+ RollupParentTriggerTestName +
+ ' is installed.'
)
);
}
@@ -587,6 +591,39 @@ public with sharing class RollupController {
}
}
+ /**
+ * Call salesforce API to get current max supported API version
+ */
+ private String getNewestApiVersion() {
+ HttpRequest req = new HttpRequest();
+ req.setMethod('GET');
+ // submit a Versions request
+ req.setEndpoint(URL.getOrgDomainUrl().toExternalForm() + '/services/data/');
+ // Salesforce REST API Dev Guide says this endpoint doesn't need authentication
+
+ try {
+ Http http = new Http();
+ HTTPResponse res = http.send(req);
+ if (res.getStatusCode() != 200) {
+ return FALLBACK_COMPONENT_API_VERSION;
+ }
+ String body = res.getBody();
+ List