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
1 vote
1 answer
77 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'...
user avatar
  • 15
5 votes
1 answer
108 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 ...
user avatar
0 votes
0 answers
44 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 ...
user avatar
0 votes
0 answers
48 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 ...
user avatar
0 votes
0 answers
20 views

Resolve PMD:Validate CRUD permission before SOQL/DML operation on Dynamic SObject

I'm familiar with resolving this pmd violation when the object is known and can be checked like if (Account.SObjectType.getDescribe().isupdateable()) {} but what if the Object is not known before ...
user avatar
0 votes
1 answer
49 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 ...
user avatar
0 votes
1 answer
79 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 ...
user avatar
  • 765
0 votes
1 answer
51 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 ...
user avatar
  • 1
0 votes
1 answer
71 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 ...
user avatar
4 votes
1 answer
188 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 ...
user avatar
0 votes
1 answer
80 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 ...
user avatar
0 votes
1 answer
636 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 ...
user avatar
  • 1,095
0 votes
1 answer
435 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>();...
user avatar
0 votes
1 answer
147 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) { } ...
user avatar
  • 99
1 vote
1 answer
136 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.......
user avatar
0 votes
2 answers
156 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 ...
user avatar
3 votes
1 answer
141 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 = ...
user avatar
  • 99
0 votes
1 answer
361 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 ...
user avatar
  • 99
1 vote
1 answer
120 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 ...
user avatar
  • 683
0 votes
1 answer
331 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(...
user avatar
  • 683
0 votes
1 answer
121 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 ...
user avatar
  • 503
11 votes
0 answers
199 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 ...
user avatar
  • 130k
1 vote
1 answer
45 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 ...
user avatar
  • 479
1 vote
0 answers
301 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> ...
user avatar
0 votes
1 answer
3k 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,...
user avatar
1 vote
1 answer
1k 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{ ...
user avatar
0 votes
1 answer
694 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 ...
user avatar
  • 512
0 votes
0 answers
180 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....
user avatar
0 votes
0 answers
828 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 ...
user avatar
5 votes
2 answers
2k 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 ...
user avatar
-1 votes
1 answer
449 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/...
user avatar
0 votes
1 answer
338 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....
user avatar
0 votes
2 answers
560 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 = '...
user avatar
0 votes
0 answers
320 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) { ...
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 ...
user avatar
  • 125
1 vote
1 answer
2k 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 ...
user avatar
0 votes
1 answer
348 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:\...
user avatar
0 votes
0 answers
365 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....
user avatar
0 votes
0 answers
19 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 ...
user avatar
  • 81
0 votes
1 answer
497 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 =:...
user avatar
5 votes
0 answers
484 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 ...
user avatar
4 votes
2 answers
2k 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 ...
user avatar
  • 321
9 votes
1 answer
10k 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 ...
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 ...
user avatar
  • 8,360
11 votes
3 answers
15k 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 ...
user avatar
  • 8,360
6 votes
2 answers
641 views

Silence the AvoidGlobalModifier warning in @RestResource Apex controller

I have a simple Apex Controller annotated with @RestResource. According to the documentation, this must be declared global, but the static analysis complains due to the AvoidGlobalModifier PMD rule. ...
user avatar
4 votes
1 answer
2k views

Using PMD in IntelliJ IDE with Illuminated cloud 2

I am trying to use PMD in IntelliJ IDE using illuminated cloud. When I run PMD using pre-defined rules, no violations are reported. When I try to import custom rules from PMD's website, it does not ...
user avatar
  • 663
0 votes
1 answer
1k views

VfUnescapeEl PMD Fix for VF Page

Can anyone provide your insights for fixing the VfUnescapeEl PMD issue in visualForce Page. For better understanding please see the below code snippet <script type="text/javascript" src="/...
user avatar
0 votes
1 answer
901 views

Error method has a cyclomatic complexity and nested if error

Please find the below trigger handler which is not passing PMD rules. Error 1."Deeply nested if..then statements are hard to read" for following class: Public Class LeadTriggerHandler { //Set ...
user avatar
0 votes
3 answers
1k views

PMD Apex static code analyser on Mac

I have used PMD before on Windows. I found this video very helpful for advising me of the correct PMD command to input for Windows. I want to use PMD on Mac. I have installed PMD (I know it's ...
user avatar