Affects PMD Version:
6.32.0+
7.0.0
Rule: ApexSuggestUsingNamedCred
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_apex_security.html#apexsuggestusingnamedcred
Description: Warning is "Consider using named credentials for authenticated callouts (rule: Security-ApexSuggestUsingNamedCred)apex pmdApexSuggestUsingNamedCred", but I am using Named Credentials with merge fields, the same way the official Salesforce docs list them: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_named_credentials_merge_fields.htm
Code Sample demonstrating the issue:
private static HttpRequest buildHTTPRequest(String endpoint, String httpMethod, String body) { HttpRequest req = new HttpRequest(); req.setEndpoint(endpoint); req.setMethod(httpMethod); req.setHeader('Authorization', '{!$Credential.AuthorizationMethod} {!$Credential.Password}'); req.setHeader('Content-Type', 'application/json'); req.setBody(body); return req; }
Expected outcome:
req.setHeader('Authorization', '{!$Credential.AuthorizationMethod} {!$Credential.Password}');
shouldn't suggest using Named Credentials because it is using Named Credentials, through merge fields.
Running PMD through: Visual Studio Code
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4