Skip to main content
36 votes
Accepted

Can we access class properties dynamically with Object class?

Unfortunately, that feature is not supported via default Apex. But there is something, which is possible to do in this case -- create custom get method, and extend your classes from your base custom ...
kurunve's user avatar
  • 4,319
17 votes

Can we access class properties dynamically with Object class?

Using an internal map for this purpose has the advantage that get/set access performance doesn't degrade as more fields are added: public class XYZ { private Map<String, Object> m = new ...
Keith C's user avatar
  • 136k
16 votes

LWC get url parameters in Community

Another approach with using URL.searchParams: The searchParams readonly property of the URL interface returns a URLSearchParams object allowing access to the GET decoded query arguments contained ...
Oleh Berehovskyi's user avatar
15 votes
Accepted

Is there an Apex Linter out there?

There's PMD Apex, which has a bunch of linting, plus various rules for SOQL inside loops, etc. That's the only one I'm aware of today.
sfdcfox's user avatar
  • 497k
15 votes

LWC get url parameters in Community

The best way to get params from URL is use CurrentPageRefference. currentPageReference.state allows you to get params. import { LightningElement, wire } from 'lwc'; import { ...
Piotr Gajek's user avatar
  • 2,784
12 votes
Accepted

LWC get url parameters in Community

If the question was if the LWC Framework provide an utility - then no not that i am aware of. Which means you can use every js snippet you will find somewhere in the web like parameters = {}; ...
Renji-xD's user avatar
  • 2,791
8 votes

How do I cover 'addError' in test class

A more complete example based on d_k answer, but handles the exception not being thrown, as pointed out by Adrian Larson. @isTest public static void testMethod() { // arrange Boolean ...
Robs's user avatar
  • 9,396
7 votes
Accepted

How to cover 'addError' in a test class?

You need to run as a user who is not a System Administrator. You already set one up, now you just need to call system.runAs. system.runAs(u) { // delete here and it should fail }
Adrian Larson's user avatar
  • 151k
7 votes

Method does not exist or incorrect signature: void format(String) from the type Date

Date does not have a format() method accepting a string. That method is available only on DateTime. You can create a DateTime from a Date and simply use a format string that does not include time-...
David Reed's user avatar
  • 93.2k
7 votes
Accepted

Explanation of an notation List<name.test> nameList

This is probably because the clas Name contains the definition of another inner class like this: public class name{ public class test{ } } If so, you have to specify the parent class name ...
Martin Lezer's user avatar
  • 7,295
6 votes
Accepted

How do I cover 'addError' in test class

Do this in catch block : Boolean expectedExceptionThrown = ex.getMessage().contains('Script-thrown exception') ? true : false; System.assertEquals(expectedExceptionThrown, false); OR System....
d_k's user avatar
  • 1,301
5 votes

Test Classes are included in code coverage

I ran in to this issue. What could have happened is, test class was created without @isTest annotation (at this point the class has been added to the code coverage table) and @isTest was added later (...
Avinash's user avatar
  • 2,111
5 votes

Tools for code Evaluation

You can try out CheckMarx tool for source code analysis. I have used that and it is very useful. For more information refer checkmarx It verifies: Cross-Site Scripting (XSS) Cross-Site Request ...
Santanu Boral's user avatar
5 votes

Not able to cover catch block in test class

The simple answer here is that you need to cause an exception to be thrown. The golden rule of unit testing is you only gain coverage for code that is executed as part of a test method. No exception ...
Derek F's user avatar
  • 62.8k
5 votes

Accessing Object properties

It is (or, at least, used to be) faster to use a variable if you're going to use the field lots of times. See this video for lots of experimentation: https://www.youtube.com/watch?v=w6QnalRWlEE ...
Aidan's user avatar
  • 13.8k
5 votes
Accepted

Avoiding multiple If statements

Let's assume that all tests are equalities You could create a simple two-level map. Note that map keys can be sobjects. The map key will be an sobject possessing only the fields+vals for a given ...
cropredy's user avatar
  • 72.1k
5 votes

How to Document and correct indentation on apex

While I know some folks are happily and successfully using uncrustify, the formatting route that's currently recommended with the Visual Studio Code Extension Pack for Salesforce is Prettier. The ...
David Reed's user avatar
  • 93.2k
5 votes
Accepted

How does js files behave when same lwc is repeated in a component?

What sort of behavior is this? Is this expected? These are a type of "static" variables, formally called "module-scoped variables". A static variable is one that is defined, and ...
sfdcfox's user avatar
  • 497k
5 votes
Accepted

How to access existing code in Salesforce

Going through the Developer Console is one way to see/edit the existing code in your org, but probably not the preferred method. Using the Salesforce CLI (a.k.a. Salesforce DX, sfdx) is the current, ...
Derek F's user avatar
  • 62.8k
5 votes
Accepted

Optional chaining - change

The safe navigation operator still returns null if a null is in the path, so you have to check for that: if(c?.Status__c?.Contains('Released') == true){ // get the Error on this line System....
sfdcfox's user avatar
  • 497k
4 votes
Accepted

How to check the field value is same for all the records in the list?

Just cache the first one and then compare equality. It's worth noting that this approach as written below performs a case-insensitive comparison. If you want case-sensitivity, you're going to need to ...
Adrian Larson's user avatar
  • 151k
4 votes
Accepted

Ghost Text in Apex Class Editor

I have run into this issue before and fixed it by zooming in or zooming out to adjust the display. You can see that this issue has been around since at least 2013: In-Page Editor Line Distortion. For ...
Adrian Larson's user avatar
  • 151k
4 votes

Offline tool that can show dependencies between different metadata files

There are a number of tools outlined in Apex static code analysis, although most of them are online. In particular the post by Robert Sösemann on the static code analyzer that integrates with Eclipse. ...
Daniel Ballinger's user avatar
4 votes

Code Coverage=0%

This outcome is explained by considering the relationships between ContentDocument and ContentDocumentLink. It's documented Salesforce behavior that cascade-deletes do not invoke apex triggers on any ...
Morgan Marchese's user avatar
4 votes

Code Coverage Failure trigger deploy on production

To deploy a trigger to production , you will need to ensure your trigger has a test class and the class needs to cover at least 75% of the lines of code . Looks like you are writing the trigger for ...
Mohith Shrivastava's user avatar
4 votes

How to Document and correct indentation on apex

Uncrustify It only works if you enable an override (by default, it works on other languages). I found this blog post that explains more. You need to create a configuration file (uncrustify.create), ...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

Prettier formatting tabSize and printWidth

After running the install command: npm install --save-dev --save-exact prettier prettier-plugin-apex Restart VS Code. Then, go to View > Command Palette... and find the command "Prettier: Create ...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

Help fixing Apex Error

It's probably caused by this update - https://admin.salesforce.com/blog/2020/critical-update-ensure-users-have-access-to-auraenabled-methods which removed automatic access to @AuraEnabled methods for ...
eaeaoo's user avatar
  • 928
4 votes
Accepted

Better way of searching for values in apex list

Lists are not a great match for this problem. What you should be looking at instead is a Set. The Set class/type provides some useful methods, containsAll(), retainAll(), removeAll() Thinking in terms ...
Derek F's user avatar
  • 62.8k
4 votes

How does js files behave when same lwc is repeated in a component?

The behavior of the helper file is as it is expected. As you need to hold different states for each component in the iteration you can do something like this in the helper.js. export default class ...
Rahul Gawale's user avatar
  • 12.2k

Only top scored, non community-wiki answers of a minimum length are eligible