0

I have a process builder that creates a case when an Account name has been changed. My company builds software for hospitals, which fairly frequently change ownership and names. The case is to alert our interface team of the change so that they can update the name on the client's UI.

These cases seem to be more frequent than necessary because our users will update an apostrophe or spacing. Is there a way to limit the case creation to only those where the field is different enough? Such as excluding if the only difference between the field values is whitespace or characters.

It is not an option to limit the ability to change account names to certain users.

1

You can take this approach to find out the change. Create a boolean field on Account object like isNameChanged.

Write an after update trigger on Account object to identify what the values have been changed. If those values are not whitespace or characters then make isNameChanged=true.

Based on the boolean field, you can fire process builder's process to create a case.

0

I think this is one where you'll need to drop to Apex to detect those "changes" that don't really make a difference.

The String.replaceAll() method is probably the closest you can get as far as detecting when a change is completely minimal or doesn't need to fire actions. Apex doesn't have great support for manipulating and filtering strings based on character classes, but it does offer regular expressions that we can use to meet the need.

You could write a method like this in Apex:

public static Boolean areStringsEquivalent(String one, String two) {
    static final String regex = '[^A-Za-z0-9]+';

    return one.replaceAll(regex, '') == two.replaceAll(regex, '');
}

This uses a regular expression to match all characters that aren't in the negated character class [^A-Za-z0-9] (all alphanumeric characters) and replace them with an empty string. It then performs a case-insensitive comparison on the remaining string.

Your code could call a method like this with the old and new value of Account.Name (from a trigger) and then make a determination on how to proceed.

Note that this specific regular expression may have unexpected side effects with international text (where, for example, Russian or Hebrew names would just end up looking like blanks, and would always be evaluated as non-changing).

You might also find the method String.getLevenshteinDistance(stringToCompare) useful. The Levenshtein distance is the number of individual character changes needed to turn one string into another - an approximation of their similarity ranging from 1 to the length of the longer string.

I don't think Levenshtein distance alone is enough to address your objective, because the Levenshtein distance between (forgive my example) "ACME Carp & Halibut" and "ACME Crap & Halibut" is the same as the Levenshtein distance between "Smith Produce" and "Smith's Produce". In both cases, two character changes need to occur to make one from the other, but one is embarrassing and the other more or less aesthetic.

  • Also, getLevenshteinDistance might be of some use; you could identify how many characters have changed and only update if more than a certain threshold is met. – sfdcfox Jul 25 '18 at 16:17

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.