+ Start a Discussion
Ray Lee 18Ray Lee 18 

split the first and last name in lead

Hi,

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.

Thanks!
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.

 Thanks

All Answers

KrishnaAvvaKrishnaAvva
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
split(regExp)
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.
Signature

public String[] split(String regExp)
Parameters

regExp
    Type: String 

Return Value

Type: String[]
Note

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.
Usage

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.
Example

In the following example, a string is split using a backslash as a delimiter.
view source
print
?
01
	public String splitPath(String filename) {
02
	    if (filename == null)
03
	        return null;
04
	    List<String> parts = filename.split('\\\\');
05
	    filename = parts[parts.size()-1];
06
	    return filename;
07
	}
08
	 
09
	// For example, if the file path is e:\\processed\\PPDSF100111.csv
10
	// This method splits the path and returns the last part.
11
	// 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
Hi, 

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.

 Thanks
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.

Thanks