1

I'm trying to make a custom field that uses a formula to generate a hash by another field.

In short, the idea is: Use field partnerCode to generate a MD5 hash. Something like md5(partnerCode)

I've already seen Crypto.generateDigest, but it seems that formulas don't allow to call Apex classes and I have no idea how to join it :(

Is there a better way to do it?

2
  • 2
    MD5 is cryptographically broken. Consider using a more modern hash algorithm.
    – David Reed
    Dec 14 '20 at 15:19
  • Depending on your use case, using an Encrypted Field may meet your requirement if you need to show hashed values to certain users and let privileged users see the original value. If not, then you will need to use Apex as Derek F has pointed out. Formula fields don't have access to cryptographic functions.
    – nbrown
    Dec 14 '20 at 19:36
2

This cannot be done via formula field (or any of the other declarative tools we have such as workflow, flows, or process builder). The functions you can use with formula fields are documented in the Formula Operators and Functions page.

You'll need to write some Apex to accomplish this. It could be part of a trigger (this would be a good fit for a before trigger context) or as a class with an @invocableMethod() annotation for use with process builder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.