+ Start a Discussion
Ray Lee 18Ray Lee 18 

split the first and last name in lead


When lead created from our web form, visitors put their full name into the FIRST NAME field.

I need a way to find how many words in the field and then split it and update it back to the first and last name field in the lead.

Here is an example when the lead created

First Name: Johnny Clark
Last Name: [not provided]

I want to split it out correctly using processes builder.

First Name: Johnny
Last Name: Clark

Does anyone have any idea? please let me know.

Best Answer chosen by Ray Lee 18
Piyush Gautam 6Piyush Gautam 6
Hi Ray Lee 18,

Use below-defined formula is criteria, it will solve your problem.
FIND(" ", [Lead].FirstName)!= 0

User-added image

If found this helpful mark as solved.


All Answers

Hi Ray,
If its always 2 words you can split it with white space. If the user can enter more than 2 hours eg : Johnny Jack Clark in that case you have to decide which 2 words you want as first name and the remaining as last name.

Split functionality : More finormation : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm
Returns a list that contains each substring of the String that is terminated by either the regular expression regExp or the end of the String.

public String[] split(String regExp)

    Type: String 

Return Value

Type: String[]

In API version 34.0 and earlier, a zero-width regExp value produces an empty list item at the beginning of the method’s output.

See the Java Pattern class for information on regular expressions.

The substrings are placed in the list in the order in which they occur in the String. If regExp does not match any part of the String, the resulting list has just one element containing the original String.

In the following example, a string is split using a backslash as a delimiter.
view source
	public String splitPath(String filename) {
	    if (filename == null)
	        return null;
	    List<String> parts = filename.split('\\\\');
	    filename = parts[parts.size()-1];
	    return filename;
	// For example, if the file path is e:\\processed\\PPDSF100111.csv
	// This method splits the path and returns the last part.
	// Returned filename is PPDSF100111.csv
Piyush Gautam 6Piyush Gautam 6
Hi Ray Lee 18,

You can achieve this functionality by Process Builder. You need to update the First Name by splitting the Name based on the white space and same need to be done for the Last Name. Below are the formulas that need to be put inside Process Builder.

FIRST NAME:   LEFT([Lead].FirstName , FIND(" ", [Lead].FirstName) ) 
LaAST NAME:  RIGHT([Lead].FirstName , LEN([Lead].FirstName)-FIND(" ", [Lead].FirstName) ) 

If found this helpful mark as solved.

Process Builder

Ray Lee 18Ray Lee 18

Thanks for your formula and it works, the only problem is I need to find a way to check if the lead.firstname has " " or not before executing those action.

Without that checking in the criteria of the processes builder, if it is only one word in the first name, it will update the first name to become the last name, because those only apply when the first name must contain like "Johnny Clerk" and not "Johnny"

Does anyone know how to put the condition to check the space in processes builder formula? I tried the first name contains " " or ' ' and those get me syntax errors inside the action.

Thanks again!
Piyush Gautam 6Piyush Gautam 6
Hi Ray Lee 18,

Use below-defined formula is criteria, it will solve your problem.
FIND(" ", [Lead].FirstName)!= 0

User-added image

If found this helpful mark as solved.

This was selected as the best answer
Ray Lee 18Ray Lee 18
Hi Plyush Gautam, 

It works perfectly and thanks you very much!
Piyush Gautam 6Piyush Gautam 6
Please mark as solved.