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 be Test010120185 and we want to prevent a creation of a record with the same values (same key).
The problem is that the key can be very long (more than 255 characters) and we can't use long text field (you can't make it unique).
So we thought about hashing the key with
String hash = EncodingUtil.convertToHex(Crypto.generateDigest('SHA256', Blob.valueOf(key)));
And it works.
BUT can I rely on it ? Is there a possibility that 2 records with different keys would generate the same hash ?