Questions tagged [pmd]

PMD is an open-source code analyser that scans source code and looks for potential problems like possible bugs, ugly or overcomplicated code and finds security flaws. It was recently ported from Java to Apex.

Filter by
Sorted by
Tagged with
2 votes
0 answers
61 views

How to use a Named Credential within an Auth. Provider Plugin?

I'm currently working on an Apex Auth Provider Plugin, and I've encountered a PMD code scan error with the following message: Suggest named credentials for authentication. Rule: Security-...
Josue0117's user avatar
1 vote
1 answer
110 views

How to Resolve the Apex PMD Rule "ApexOpenRedirect"

community. I am currently working on a custom plugin for an Auth Provider in Apex and have encountered the error message "Apex classes should safely redirect to a known location (rule: Security-...
Josue0117's user avatar
2 votes
1 answer
69 views

Best Practices for CRUD/FLS/SHARING checks in unmanaged code

I'm auditing an ORGS unmanaged Apex and trying to form a concrete framework for when I care about PMD warning for ApexCRUDViolation & ApexSharingViolations. It's always been my understanding that ...
NSjonas's user avatar
  • 10k
0 votes
0 answers
447 views

I encountered an error with Apex PMD while using VS Code

Static Analysis Failed. Error Details: PMD Command Failed! Enable "Show StdErr" setting for more info. I already enable this setting inside vs code but still getting same error
Rohit Kumar's user avatar
0 votes
1 answer
91 views

How to remove a PMD rule for SOQL CRUD Operation for Setup Objects?

How can I remove Apex PMD rule violation for SOQL CRUD operation for Setup objects like Profile, Groups. I am using @SuppressWarnings right now but is there any other turn around so that I can use ...
sfdcStag's user avatar
1 vote
0 answers
325 views

Transport False-Positive comments to Checkmarx report

I want to find the best way to address false positives in the Checkmarx report. One of the points I am investigating is how to make the Checkmarx report to display the false positive comment that has ...
Manuel Moya's user avatar
1 vote
1 answer
3k views

How to exclude PMD rule from specific classes/directories

We have a folder within our project that we would like to exclude from one PMD rule. For example, we want the rule FieldNamingConventions, but we just don't want it to run on a specific directory. We'...
Peter J's user avatar
  • 25
6 votes
1 answer
303 views

Best (commercial) Scanner to stay prepared for Security Review

For ISVs to be safe to (re)submit their app for Security Review without issues Checkmarx still is the only authoritative tool. But it is also cumbersome and limited as: Community Scanner is limited ...
Robert Sösemann's user avatar
0 votes
0 answers
641 views

PMD Configuration For Salesforce

I am new PMD tool, i did below steps to configure PMD for salesforce and unable to proceed. Can anyone please help me here. Please tell me if i am missing something. I have downloaded the PMD for ...
bheema donthi's user avatar
2 votes
0 answers
270 views

Error While trying to add custom rule for Apex PMD

I'm trying to add some custom rule for my apex classes in PMD. But while trying to run designer command to PMD to create the Xpath for the rule, I'm getting below error: You seem to be missing the ...
Salesforcegeek's user avatar
0 votes
1 answer
250 views

How do I write a rule for Apex PMD that allows it to recognize custom objects?

I'd like to eliminate any warnings from Apex PMD that triggers alerts on custom objects for my Salesforce organization. Is there any way to add my custom objects to the linter? For example, when I am ...
alfwhfwef's user avatar
0 votes
1 answer
957 views

Apex PMD "Validate CRUD permission before SOQL/DML operation" on Lists of Objects

I'm trying to clean up my PMD Errors in my code, and I noticed that I'm getting the "Validate CRUD permission before SOQL/DML operation" error when updating a list of a custom object, but ...
aaron's user avatar
  • 855
0 votes
1 answer
227 views

VfUnescapeEl PMD fix for salesforce static resource page

We are getting VfUnescapeEl error in our sfdx report on the following line : <a href="{!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))}{{x.Id}}">...</a> here, x.id will be ...
Gourav's user avatar
  • 1
0 votes
1 answer
423 views

Necessity to resolve all PMD issues for security review

We generated a pmd report using sfdx, is it necessary to resolve all the sfdx report issues to pass the salesforce security review or those are just warnings and can be ignored to pass the security ...
Suyash Mandhana's user avatar
4 votes
2 answers
684 views

How to integrate Apex PMD with husky and lint-staged?

I am currently working on the IDE setup for a SFDX project. In my opinion the process for ensuring good code quality already starts in the developer's IDE. Therefore, for UI components, I already have ...
Sebastiano Schwarz's user avatar
0 votes
2 answers
569 views

After PMD Apex code change, getting alot of errors and can not deploy code

I recently had to modify my Apex class code because I ran a PMD Apex scan. After reading the SF docs, I made changes and the PMD Scan passed the code. However, when I started to deploy code, I am ...
user3688231's user avatar
0 votes
1 answer
2k views

How to use Wrapper Class in constructor and call it in Queueable?

My Queueable Apex class worked fine before but after discovering Apex PMD ruleset, found that using >4 parameters in any method or constructor is not best practice. I tried searching up answers ...
compski's user avatar
  • 1,251
0 votes
1 answer
1k views

Avoid Logic in Triggers PMD with Safe Navigator

trigger WS_MilestoneChange on pse__Milestone__c(before insert, before update, after update, after insert) { Map<Id, pse__Milestone__c> updateMilestones = new Map<Id, pse__Milestone__c>();...
Maxwell Newberry's user avatar
0 votes
1 answer
552 views

Apex Batch and PMD rule EmptyStatementBlock

Does anyone know is there any option how to fix this PMD rule: EmptyStatementBlock in case when the error/violations/rule is reported for: global override void finish(Database.BatchableContext bc) { } ...
mhdev's user avatar
  • 119
1 vote
1 answer
285 views

PMD showing errors for one class, but not another class with the same issue

I just installed PMD and its pretty janky from my experience, for example I have two classes and it shows the "same name" error for one class but completely ignores it for the other class.......
happyLion's user avatar
0 votes
2 answers
291 views

Discover Schema of Source + Metadata XML formats

The Open Source Static Analyser PMD is now supporting not only Apex but also rules on arbitrary XML metadata. Using flexible XPath expressions that verify the structure and attributes of XML. I am ...
Robert Sösemann's user avatar
3 votes
1 answer
461 views

UnusedLocalVariable Salesforce

I am trying to resolve some of PMD warnings in Apex (Salesforce), currently I am working on this one UnusedLocalVariable and here is the code snippet where the problem is: DateTime startDate = ...
mhdev's user avatar
  • 119
1 vote
1 answer
1k views

PMD and Salesforce

Does anyone maybe know how to disable some rules from Apex PMD, for example, I want to disable this one "ClassNamingConventions". I don't want to show me warning related to that rule in .csv ...
mhdev's user avatar
  • 119
1 vote
1 answer
295 views

What are the differences between using sObject.sObjectType.getDescribe() and Schema.sObjectType.<sObject>

Let's say we have //if(Schema.SObjectType.GroupMember.isCreateable()){ if(GroupMember.sObjectType.getDescribe().isCreateable()) { insert usersToInsert; } commented line raises ...
pincet's user avatar
  • 839
0 votes
1 answer
885 views

PMD rises `Validate CRUD permission before SOQL/DML operation` [duplicate]

Let's say we have if(Schema.SObjectType.PermissionSetAssignment.isCreateable()){ List<GroupMember> usersToInsert = new List<GroupMember>(); for(...
pincet's user avatar
  • 839
0 votes
1 answer
478 views

Apex Class - formal parameters must follow specific conventions

I have this small class which has a red line under the method name like in the snip. I believe it has something to do with the parameter naming convention, not sure what I am doing wrong here. This is ...
sumchans's user avatar
  • 641
12 votes
0 answers
390 views

Is there a reliable way to have WITH SECURITY_ENFORCED applied to all queries?

I've just gone through a biggish code base making sure that WITH SECURITY_ENFORCED is set on every query. Most were, but for some recent additions, it hadn't been included. For managed packages that ...
Keith C's user avatar
  • 135k
1 vote
1 answer
56 views

What to check in a test method that doesn't modify or return a value?

I have a queueable class that gets a token then enqueues another queueable with the retrieved token. The second queueable do the DML and everything. This TokenQueueable class doesn't modify or return ...
Lafexlos's user avatar
  • 499
1 vote
0 answers
430 views

Validate CRUD permission before SOQL/DML operation (rule: Security-ApexCRUDViolation)

I can see an unexpected behavior with PMD rules when working with the stripInaccessible method, I have tried to insert List of Order records in my APEX class like below, private List<Order> ...
Hariprasath's user avatar
2 votes
1 answer
8k views

Apex Pmd : Apex classes should escape variables merged in DML query (rule: Security-ApexSOQLInjection)apex pmdApexSOQLInjection

I have referred pmd ruleset but could not find the exact solution for this,please help? opportunityListOH = new list<opportunity>(); String query = 'Select Id, Name, StageName,Freeze__c,...
Indresh Bhargav's user avatar
2 votes
1 answer
3k views

Apex pmd : Validate CRUD permission before SOQL/DML operation (rule: Security-ApexCRUDViolation)apex pmdApexCRUDViolation)

I have used WITH SECURITY_ENFORCED in the query still getting this error.Can someone suggest a solution? Public void freezeMethod (){ disabledFreez = true; try{ ...
Indresh Bhargav's user avatar
0 votes
1 answer
2k views

PMD check fails: validate CRUD before DML Operation

I have a list of sObjects. In this list I have records of Account,Contact and Opportunity which needs to be updated. so before updating the list I am doing CRUD check on Account , Contact and ...
sfdc07's user avatar
  • 584
0 votes
0 answers
408 views

APEX PMD Security Error

Added Chrome PMD Extension Salesforce Advanced Code Searcher to run PMD script for my Apex Controller. Below Code doesn't shows any security error. if( Programs__c.SObjectType....
user3214361's user avatar
0 votes
0 answers
2k views

PMD Apex ExcessiveClassLength & ExcessivePublicCount Rule error

Getting the following error message when I Ran the PMD scripts for Apex Class. ExcessiveClassLength -- Avoid really long classes. ExcessivePublicCount -- This class has a bunch of public methods and ...
user3214361's user avatar
5 votes
2 answers
4k views

PMD Apex ExcessiveParameterList Rule error

When I run the APEX PMD, getting Design Error for the Below method. ExcessiveParameterList Avoid long parameter lists. Checked below link not able to solve this issue, Can anyone please help me on ...
user3214361's user avatar
-1 votes
1 answer
775 views

Apex Security rule Check of Soql/ DML [closed]

Trying to add Security Check on SOQL/ DML action in my Apex class. Gone through the following link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/...
SFDC_Beginner's user avatar
0 votes
1 answer
776 views

PMD Security - Apex Suggest Using Named Cred

Getting Suggest named credentials for authentication error in my PMD script. http http = new http(); httpRequest request = new httpRequest(); request.setMethod('POST'); request....
user3214361's user avatar
0 votes
2 answers
2k views

PMD Security error - Apex Suggest Using Named Cred

I'm getting ApexSuggestUsingNamedCred **Suggest named credentials for authentication** in Below Code. Blob headerValue = Blob.valueOf(username + ':' + password); String authorizationHeader = '...
SFDC_Beginner's user avatar
0 votes
0 answers
472 views

fls check and crud checking on generic

I have AuraEnabled method in my class so lwc component can send an id of sobject(could be any objects) and this method can delete it. @AuraEnabled public static void deleteRecord(String recordId) { ...
Shinya Koizumi's user avatar
1 vote
1 answer
1k views

How to properly use stripInaccessible for PMD ApexCRUDViolation [closed]

On triggers I have some PMD ApexCRUDViolation errors. I see on the winter/spring 20 release notes a new apex function "stripinaccessible" to manage records/fields permissions. Could you have some ...
David-IT's user avatar
  • 135
1 vote
1 answer
5k views

Why apex classes should declare a sharing model if dml or soql is used?

I have installed Apex PMD in my visual studio code for the static analysis of my code. I have a global class and inside it, I have written some DML/SOQL query. The static analyzer shows a warning ...
Noor A Shuvo's user avatar
0 votes
1 answer
1k views

Pmd analysis command not giving any output

I am running pmd command to fetch the report in html format but every time it gives me error Following command is used pmd.bat -d D:\TestSBX02\AllData\force-app\main\default\classes -f html -R D:\...
psalesforce1989's user avatar
0 votes
0 answers
450 views

Resolve PMD's ApexCRUDViolation

I'm having trouble resolving the ApexCRUDViolation for this method. It seems similar to this example, am I handling the fields queried via relationship correctly (e.g. ChargentOrders__Order__r....
Peter Yao's user avatar
0 votes
0 answers
23 views

Are there any recent tools to help find org health?

I am looking to get metrics using Apex PMD on the status of all metadata in our org. Are there any ways to compile all of this data or any other tools that will be able to compile this data and ...
J1593's user avatar
  • 81
0 votes
1 answer
640 views

ApexCRUDviolation Fix

How to fix ApexCRUDViolation for inner query. Below is the query. proposal = [select Id, Name,(Select Id From PQConfig__Configurations__r) From Proposal__Proposal__c Where Proposal__Opportunity__c =:...
diwakar g's user avatar
6 votes
0 answers
728 views

How to create custom rules for PMD Apex static code analyzer?

How can I create custom rules for PMD? For example, if I want to create a rule to say 'all code should be in allman style and therefore, any line with { should be the only character on the line', how ...
Andy Hitchings's user avatar
4 votes
2 answers
3k views

Apex PMD: Avoid empty block statements

Perhaps this isn't the place for this -- but it looks like a good place to start. I'm using Apex PMD code analysis (within Visual Studio Code) and it's throwing off the following for an interface ...
Michael Paler's user avatar
9 votes
2 answers
15k views

Apex classes should escape/sanitize Strings obtained from URL parameters: How?

I have the following line of code in my visualforce controller. caseId = ApexPages.currentPage().getParameters().get('caseId'); I am using PMD, which is a static code analyzer. It complains me of ...
Sohan Shirodkar's user avatar
1 vote
1 answer
2k views

Batchable & Schedulable class has cyclomatic complexity of 48

Background I have a class which implements Database.Batchable<Sobject> and Schedulable and when I run PMD I get this problem: The class 'MyClassBatchJob' has a total cyclomatic complexity of ...
Robs's user avatar
  • 9,187
11 votes
3 answers
25k views

Apex PMD: Problem: Validate CRUD permission before SOQL/DML operation

Background I am using the Apex PMD plugin for VS Code and it's giving me this problem: Validate CRUD permission before SOQL/DML operation For this line of code: insert contentVersion; Which is ...
Robs's user avatar
  • 9,187