Questions tagged [hashcode]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
41 views

when does the Map return null?

class MapTask { public static void main(String[] args) { Map<KeyClass, Object> map = new HashMap<>(); KeyClass key = new KeyClass(); Object value = new ...
Vlad's user avatar
  • 1
0 votes
1 answer
160 views

How to generate HMAC SHA-256

I have gone through these, can we generate hmac in SSJS Marketing cloud Is it possible to perform HMAC SHA1 encoding with Ampscript? But check again as a new question, if there is any latest update ...
Vishal Kumar C V's user avatar
2 votes
1 answer
137 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 ...
Shohrat Muhamov's user avatar
0 votes
2 answers
456 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 ...
Kowalek's user avatar
0 votes
2 answers
732 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, ...
Tyler Zika's user avatar
  • 2,860
12 votes
1 answer
388 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 ...
Keith C's user avatar
  • 136k
1 vote
1 answer
472 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 ...
lambad's user avatar
  • 385
0 votes
1 answer
2k 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....
GroundToCloud's user avatar
2 votes
1 answer
210 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 ...
Robs's user avatar
  • 9,330
0 votes
1 answer
375 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 ...
osos9's user avatar
  • 559
0 votes
1 answer
262 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 ...
Kaushal one's user avatar
11 votes
1 answer
553 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 ...
Aidan's user avatar
  • 13.6k
7 votes
2 answers
908 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 ...
Daniel Ballinger's user avatar
2 votes
0 answers
314 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 ...
Robert Sösemann's user avatar
3 votes
1 answer
474 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<...
Mossi's user avatar
  • 3,926
6 votes
1 answer
535 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 ...
Adrian Larson's user avatar
  • 150k
5 votes
3 answers
190 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> ...
Martin.Kona's user avatar
1 vote
1 answer
429 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 ...
Hemendra Singh Bhati's user avatar
0 votes
1 answer
601 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 ...
Yifei Pei's user avatar
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: @...
Keith C's user avatar
  • 136k
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(...
Alex Tennant's user avatar
  • 13.6k
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, ...
Alex Tennant's user avatar
  • 13.6k