I am working on a requirement wherein I need to extract first letter of the user names and show on the page.However the last names can contain spaces. In such cases I need to display initials of all the last names eg Frank Robert Clark should become FRC (Robert Clark being the last name).

I know this can easily be achieved through apex. I would however be interested to know if i can achieve it without making any apex changes(as in my case it would involve creating a wrapper/map which i want to avoid) by making use of VF functions or formula field.

Right now the approach is to extract first character of first name and last name fields using the LEFT formula: {!LEFT(usr.FirstName,1)} {!LEFT(usr.LastName,1)}

  • 1
    what is the current behavior? not showing anything on the page? maybe you can share some code of how you are attempting to do this atm, and point out any specific setbacks you are encountering?
    – glls
    Aug 1, 2017 at 16:28
  • Well for now the approach is {!LEFT(usr.FirstName,1)} {!LEFT(usr.LastName,1)}. However this approach works for those with just one word last name. eg For James Clark : JC but for James Matthew Clark it comes as JM instead of JMC
    – starhunter
    Aug 1, 2017 at 16:37
  • 1
    can you update your post with that info =)
    – glls
    Aug 1, 2017 at 16:37

1 Answer 1


This is ugly... But it works. :)

LEFT(  FirstName , 1) + LEFT ( LastName, 1) +
IF(CONTAINS(LastName, ' '), MID( LastName, FIND(' ', LastName) + 1, 1), '')

You will have to add a similar if statement to account for hyphens as well.. and perhaps single apostrophes too.

  • This helps. However the requirement is for multiple words in last name. eg : Frank Matthew Henry Clark . I am afraid the formula might not work for such cases.
    – starhunter
    Aug 3, 2017 at 8:48
  • @starhunter You are correct, and I was afraid of that.
    – JRiffe
    Aug 3, 2017 at 15:47
  • @starhunter How many names do you need?
    – JRiffe
    Aug 3, 2017 at 20:31
  • @starhunter I have created a particularly nasty and complicated formula for up to 4 Last names, but it accounts for spaces as dividers only. Then I ran into Salesforce Limits. I can update my answer if you'd like to see it.
    – JRiffe
    Aug 3, 2017 at 20:44
  • There is no limit in my requirement. It could go to 5 and 6 words also.
    – starhunter
    Aug 4, 2017 at 6:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .