Questions tagged [hashcode]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
21
votes
2answers
879 views

hashCode() is never called when adding to Maps and Sets

Given the following Apex class, which implements equals() and hashCode() as per the Using Custom Types in Map Keys and Sets documentation: public class Foo { private Integer x; public Foo(...
10
votes
2answers
896 views

System.hashCode broken on Id properties of SObjects?

Just wasted some time trying to get a big business logic unit test to pass and tracked it down to this. Here is a failing test demonstrating just the problem of using System.hashCode for Id values: @...
10
votes
4answers
2k views

Is there a way to generate a unique hashcode for an in memory SObject that does not yet have an Id?

When SObjects are used as Map keys they are compared by field values, so for example: Account a = new Account(); Account b = new Account(); System.debug(a == b); // Prints true Map<SObject, ...
12
votes
1answer
294 views

System.hashCode still broken for Id

Five years ago there was System.hashCode broken on Id properties of SObjects? and I've just run into it again today. You can see the problem by running this test case: @IsTest static void ...