Questions tagged [hashcode]
The hashcode tag has no usage guidance.
20
questions
2
votes
1
answer
43
views
Generate Cybersource digest in Apex
Cybersource is asking to generate a digest from payload using byte array. However we don't have bytes in apex. I'm getting SHA-256=k3t9b6mL4zCMDTOi7N1uLQMu9XxrjwOr5yRXnTG0G1A= hash when I try to ...
0
votes
2
answers
355
views
Salesforce why hashcode method is not working
Today I have written a simple class to check the behaviour of hashCode in the sfdc.
Related to documentation salesforce:
"Uniqueness of set elements of user-defined types is determined by the
...
0
votes
2
answers
406
views
Implementing hashCode() with more than two variables
How do I implement hashCode() for a custom class with more than 2 variables? From the docs, the example only has two values used:
return (31 * x) ^ y;
I'm working with user data such as first name, ...
12
votes
1
answer
340
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 ...
1
vote
1
answer
359
views
SObject key of map mutated returns null but serializing returns the value
I am using a SObject as a key and mutating it. When I try to get the map value using the sobject, I get null.
However, when i serialize the value, I can see the old value stored.
Can anyone clarify ...
0
votes
1
answer
1k
views
base64 hash using HMAC SHA256
I am trying to compute the Apex equivalent of the following -
var shaBodyContent = CryptoJS.HmacSHA256(stringToSign, postman.getEnvironmentVariable("HMAC_SS"));
var b64BodyContent = shaBodyContent....
2
votes
1
answer
175
views
hashCode and equals implementation not working
I am not getting a match when using the containsKey method on a Map of this custom object type:
Custom Apex Type
public class StateTransition
{
final ProcessState CurrentState;
final Command ...
0
votes
1
answer
272
views
Prevent Duplicates using unique key
We want to prevent duplicate records of a custom object.
The key is built from 20 fields of the record, for example:
Let's say a record has Name = "Test", Date="01/01/2018", Number="5"
the key would ...
0
votes
1
answer
190
views
How do i get parameter values in decrypted format where the URL parameters are in encrypted format [closed]
Ex : https://www.abc.com/home?firstname=C1SA8WkuxUncg4SLsHeirA==&lastname=23O5jzhBJUGA9f9KwDre2A==
Actually the above first name should display as suneel and last name as test.
I have tried with ...
11
votes
1
answer
406
views
Unexpected results when using a custom class as key in Map
I thought I understood how maps are supposed to work. So, I thought I would try to be clever and use a custom class as the key in a map in Apex. The results, however have been unexpected.
It's so ...
7
votes
2
answers
784
views
How can I check if an sObject is contained by a Set after changing a field value?
This is probably best summed up with an example and quote from the documentation.
The following anonymous Apex will pass the given assertion.
Account a1 = new Account(name='a');
Account a2 = new ...
2
votes
0
answers
223
views
Build Duplicate matching rule for long text fields using a custom hashCode
To find duplicates of a custom object I planned using Salesforce.com's native Duplicate Management functionality. I was a bit disappointed to see that matching rules are not able to compare Long text ...
3
votes
1
answer
444
views
Methods equals() and hashCode() misbehaving in Map.containsKey()
Can you see why this returns true:
Map<IObject, XYZ> records1Map = getRecords(1); // returns Map<MyObject, XYZ>
Map<IObject, XYZ> records2Map = getRecords(2); // returns Map<...
6
votes
1
answer
459
views
HashCode Deduplication?
Background:
Ever since I found out you can Use Custom Types in Map Keys and Sets, I wondered if you can map data by the hashCode value. I suspect it's a bad idea.
I understand the basics of how hash ...
5
votes
3
answers
179
views
Why is record object with different id not used as key in Map?
I don't quite understand this situation and I wonder, if somebody knows where is the problem.
I' assigning in loop object as a key and simple number as his value:
Map<QuoteLineItem, Integer> ...
1
vote
1
answer
362
views
Hash Code Used In Map Keys
How is hash code generated when we use sobject as map keys in salesforce? As per the documentation, the hash code uses sobject field values to generate hash key but what if there are more than 200 ...
0
votes
1
answer
577
views
Apex equivalent of PHP sha1() and some more encoding methods
I got a PHP script to generate an encoded URL.
I need to translate this script into Apex code to generate the same URL. However, the PHP encode functions seem to work differently from Apex.
The ...
10
votes
2
answers
1k
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:
@...
22
votes
2
answers
1k
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(...
11
votes
4
answers
3k
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, ...