-4

We are having a lightning page on the community portal. The problem we are facing is as follows:

The Apex code is working fine & showing desired results only if we are setting debug logs for the logged in user to the community portal with debug level for apex code as "Finest".

But if we don't set debug logs or we set debug log with debug level for apex code other than "Finest" then apex code is not giving proper output. Also, it is not throwing an exception.

Part of code which is creating difference

The highlighted if condition is always false in second case while it is working fine in first case.

6
  • post the code snippet for better understanding Commented Jul 6, 2018 at 7:36
  • Sorry but I can't provide the whole code for security reasons but providing the part of the code where it is creating a difference:
    – user50072
    Commented Jul 6, 2018 at 7:45
  • I have updated the description with piece of code.
    – user50072
    Commented Jul 6, 2018 at 7:52
  • I am not able to see the system.debug in the code above , can you share how you call debug log .
    – unidha
    Commented Jul 6, 2018 at 7:58
  • 3
    @user50072 it is always better to paste code directly into your question, pictures of code means anyone helping you will need to transcribe from a picture instead of copy/paste into their editor.
    – JaredT
    Commented Jul 6, 2018 at 13:44

1 Answer 1

1

There is this unfortunate behaviour hashCode() is never called when adding to Maps and Sets that hides a missing or bad implementation of hashCode. When the debug level is set to "Finest", hashCode is never called and instead only equals is called. This reduces performance, but side-steps a bad hashCode method.

The contract - how equals and hashCode should co-operate - is defined in Java's base Object documentation. Also see Using Custom Types in Map Keys and Sets for a shorter description.

Note that this is only a problem where you use your own custom Apex class as a key which is not the case in the code you have posted. Is that the case elsewhere?

2
  • Thanks for the reply!!! But we are not using custom Apex class as a key in any of the Maps.
    – user50072
    Commented Jul 6, 2018 at 12:39
  • 1
    @user50072 Well that is one thing eliminated then. There is a chance there is some other variation within the platform that depends on the debug level but I would be surprised. Best you keep debugging: 99.99% of the time the problem is in our own code.
    – Keith C
    Commented Jul 6, 2018 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .