Description:
When running the DFA scanner against our codebase we are getting a NoSuchElementException: No value present exception. I've narrowed it down to when we pass a describe to a method. This is similar to https://github.com/forcedotcom/sfdx-scanner/issues/1209 so could be a duplicate.
Documentation:
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:143) ~[?:?]
at com.salesforce.rules.fls.apex.operations.ObjectBasedCheckUtil.isCrudCheckExpected(ObjectBasedCheckUtil.java:67) ~[sfge-1.0.1-pilot.jar:?]
at com.salesforce.rules.fls.apex.operations.SchemaBasedValidationAnalyzer.isCheckLevelValid(SchemaBasedValidationAnalyzer.java:199) ~[sfge-1.0.1-pilot.jar:?]
at com.salesforce.rules.fls.apex.operations.SchemaBasedValidationAnalyzer.convert(SchemaBasedValidationAnalyzer.java:174) ~[sfge-1.0.1-pilot.jar:?]
at com.salesforce.rules.fls.apex.operations.SchemaBasedValidationAnalyzer.checkForValidation(SchemaBasedValidationAnalyzer.java:77) ~[sfge-1.0.1-pilot.jar:?]
at com.salesforce.rules.fls.apex.operations.FlsValidationCentral.checkSchemaBasedFlsValidation(FlsValidationCentral.java:71)
Steps To Reproduce:
Run the DFA scanner against the following code. testFails will fail with the NoSuchElementException error and testWorks will correctly report a FLS violation.
public with sharing class OptionalIssue {
@RemoteAction @ReadOnly
public static void testFails(Account acct) {
DescribeSObjectResult describe = acct.getSObjectType().getDescribe();
if (canInsertDescribe(describe)) {
doInsert(acct);
}
}
@RemoteAction @ReadOnly
public static void testWorks(Account acct) {
if (canInsertObject(acct)) {
doInsert(acct);
}
}
public static Boolean canInsertDescribe(DescribeSObjectResult describe) {
if (describe.isCreateable()) {
return true;
}
return false;
}
public static Boolean canInsertObject(Account acct) {
if (acct.getSObjectType().getDescribe().isCreateable()) {
return true;
}
return false;
}
public static void doInsert(Account acct) {
Database.insert(acct);
}
}
Expected Behaviour:
For the scan to correctly report the FLS error for both methods.
Description: When running the DFA scanner against our codebase we are getting a
NoSuchElementException: No value present
exception. I've narrowed it down to when we pass a describe to a method. This is similar to https://github.com/forcedotcom/sfdx-scanner/issues/1209 so could be a duplicate.Documentation:
sfge.log
Steps To Reproduce: Run the DFA scanner against the following code.
testFails
will fail with theNoSuchElementException
error andtestWorks
will correctly report a FLS violation.Expected Behaviour: For the scan to correctly report the FLS error for both methods.
Desktop: