Gate a release with test evidence
Ship it safely · Advanced · 18 min · Runs in your Salesforce Developer org · Apex Path
Scenario. A deployment pipeline must refuse ambiguous results instead of treating missing evidence as success.
Choose a safe Salesforce test level and block promotion without clean results and a rollback reference.
What you will learn
A release gate fails closed: missing evidence counts as a failure.
Deploys pick a test level: RunSpecifiedTests runs just the classes you name; RunLocalTests runs every local test (no managed packages).
String.isNotBlank(value) is true only when value is not null, empty, or whitespace.
Gotcha. null > 0 is false, not an error, so if (failures > 0) return false; lets null through. Check null first.
The task
Complete the release gate so it picks a test level and only allows promotion when the evidence is complete and clean.
Examples:
- named tests present →
RunSpecifiedTests - no usable test names →
RunLocalTests - 0 errors, 0 failures and rollback
release-42→ promotion allowed; a null count → blocked
Requirements:
- Return
RunSpecifiedTestswhen at least one non-blank test name is supplied. - Return
RunLocalTestswhen the set is null, empty, or holds only blank or null names. - Block promotion when either count is null or above zero. Remember
null > 0is false. - Block promotion when the rollback reference is blank.
- Allow promotion only when both counts are zero and a rollback reference exists.
Starter code
public class AS_1E1E7AE44C28_ReleaseGate {
public static String chooseTestLevel(Set<String> testNames) {
return 'NoTestRun';
}
public static Boolean canPromote(
Integer componentErrors,
Integer testFailures,
String rollbackReference
) {
return true;
}
}
When it passes
The temporary class chooses a test level from real inputs and allows promotion only with clean counts plus a rollback reference.
You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.
‹ Build Contacts with one query and one insert · Build a secure Account service ›