You need to sign in to do that
Don't have an account?
Aardvark
Best Way to parse Account.Name?
So I have object Account.name which I need to take the last word of the string and place it at the beginning. For example, I have John and Jamie Jones and I need the custom field to read: Jones, John and Jamie
That could be surprising that a so simple question has no answer but it is very complicated with a formula because the suitable functions for this work are just missing.
We can find the first words "easily" but the formula becomes more an more complex for each new word to find at the beginning.
The last word is the most difficult to find with a formula.
FIND always starts from the beginning (left to right) so the function RIGHT is almost useless.
REGEX (for a formula field) and SPLIT are just missing.
The workaround is a trigger in Apex that will update a new field of type String with the last word at the beginning each time you create/update the object. In Apex, the last word is easy to find.
All Answers
That could be surprising that a so simple question has no answer but it is very complicated with a formula because the suitable functions for this work are just missing.
We can find the first words "easily" but the formula becomes more an more complex for each new word to find at the beginning.
The last word is the most difficult to find with a formula.
FIND always starts from the beginning (left to right) so the function RIGHT is almost useless.
REGEX (for a formula field) and SPLIT are just missing.
The workaround is a trigger in Apex that will update a new field of type String with the last word at the beginning each time you create/update the object. In Apex, the last word is easy to find.
A trigger is a workaround but ideally, that would be better to control the content of the field upstream as far as possible.
You will also have the common problem of the recursive calls because you update an object based on a field of itself.
https://help.salesforce.com/articleView?amp;language=en_US&id=000332407&type=1 (https://help.salesforce.com/articleView?amp;language=en_US&id=000332407&type=1)
A new field is not mandatory either.
We can try to build a giant formula (as long as we don't explode the compilation limit), that is likely possible if you know about many words at the maximum. Even if it is just first and last names, that could be very long.
There will be a formula for only the last word plus a formula for the first part before the last word and a third formula to concatenate the two parts.
At the end, we will have a very restricted formula that works with five or six words max. precisely (or perhaps less) but that will be restricted because of the limit size of a compiled formula.
So the four lines of code for a trigger is effortlessly.
Formula for the last word : works up to seven words.
But that is not enough in your case because you want to reformat the field so you need two other formulas and that will be a really very huge formula at end but still interesting to try perhaps.
A replacement of two spaces by one ( SUBSTITUTE(FirstLastNames,' ', ' ') has to be repeated with nested calls because you can have any number of spaces between the words. SUBSTITUTE ( SUBSTITUTE( SUBSTITUTE(FirstLastNames,' ', ' '), ' ',' '), ' ', ' ') )
Up to eight spaces otherwise you need a new nested substitute.
At the end, the formula becomes too huge for the limited compiled size.