Skip to main content

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
51 views

For stripInaccessible checks on READ operation discard unsanitized data

Salesforce does a terrible job at providing documentation for addressing errors thrown by its own tools. For example, after executing the sf scanner dfa command, we get the following error: For ...
dev4life's user avatar
  • 532
2 votes
0 answers
51 views

Salesforce code analyzer returns issue when using "as user" with dml

When I use delete with 'as user' and run sf code analyzer i get this problem: "PMDException: Error while parsing E:\testpro\force-app\main\default\classes\TestCl.cls Caused by: net.sourceforge....
Nazar's user avatar
  • 45
0 votes
1 answer
713 views

How to disable all Apex PMD warnings in VSCode?

I have set the Priority Warn Threshold to 0, but it will still show warnings as hints. Is it possible to not show any warnings? And I have also created a pmd-ruleset.xml file, but how do I configure ...
Z0q's user avatar
  • 91
0 votes
0 answers
208 views

The best way to avoid PMD.ExcessiveParameterList

I'm aware of @SuppressWarnings('PMD.ExcessiveParameterList') but from my perspective it isnt a great idea. So i prepared kinda wrapper like this public with sharing class PayloadWrapper { public ...
pincet's user avatar
  • 919
2 votes
0 answers
137 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
711 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
216 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
  • 10.2k
0 votes
0 answers
1k 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
459 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
467 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
5k 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
  • 35
7 votes
1 answer
368 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
888 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
375 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
298 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
2k 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
  • 854
0 votes
1 answer
333 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
553 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
947 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
812 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,352
0 votes
1 answer
2k 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
825 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
372 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
332 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
682 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
2k 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
391 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
  • 919
0 votes
1 answer
1k 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
  • 919
0 votes
1 answer
664 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
  • 789
12 votes
1 answer
517 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
  • 136k
1 vote
1 answer
61 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
  • 509
1 vote
0 answers
516 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
3 votes
1 answer
10k 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
3k 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
  • 624
0 votes
0 answers
503 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....
SK2889's user avatar
  • 921
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 ...
SK2889's user avatar
  • 921
5 votes
2 answers
5k 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 ...
SK2889's user avatar
  • 921
-1 votes
1 answer
945 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
1k 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....
SK2889's user avatar
  • 921
1 vote
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
533 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
6k 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
485 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
27 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
666 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
832 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