function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amol ChAmol Ch 

Split the name into first name and last name; If second string is absent then how can update??

Their is one custom field  NAME on lead object consist of two string (first and last name) seperated by space . Their are two standard field on lead object
1. First Name, 2. Last Name.  
I am updating first string of NAME field(Custom field) in the Last Name standard field and second string of NAME field in First Name of Standard Field, using workflow+ field update.
 User-added image
 
Update Last Name using Formula: LEFT( Name__c ,FIND(" ", Name__c ))
Updat First Name using Formula : MID( Name__c , FIND(" ", Name__c ), LEN(Name__c ) )
 
Now My Question is If second string in NAME string is absent then  first name field should be updated to blank because it optional field. How i can use the formula; Please Suggest
 
Note: In custom name field i'm inserting data from web to lead.
Best Answer chosen by Amol Ch
Lokeswara ReddyLokeswara Reddy
Hi Amel,
Last name is Mandatory field on the Lead object, so you should always make usre you enter both first string and last string in the Name__c,

What I suggest is
1. If Name__c is filled only with one string then populate this on Last Name standar field and 
2. If Name__c is filled with both the string then have your current logic.

You can use
If( CONTAINS(Name__c, " "), LEFT( Name__c ,FIND(" ", Name__c )), Name__c )  - for Last Name
If( CONTAINS(Name__c, " "), MID( Name__c , FIND(" ", Name__c ), LEN(Name__c )), null) - for First Name

This will even retain the value in Standard Name field even if you null of Name__c value.

All Answers

Lokeswara ReddyLokeswara Reddy
Hi Amel,

You can use this to update your first name
 BLANKVALUE(MID( Name__c , FIND(" ", Name__c ), LEN(Name__c ) ),  LEFT( Name__c ,FIND(" ", Name__c ))) 
Amol ChAmol Ch
Hi Lokeshwara, This is not getting me answer, when i'm trying, it will not allowed to saved the record.
My requirement is when second string is absent then first name field should be updated to blank.
Lokeswara ReddyLokeswara Reddy
Hi Amel,

Here you go
If( CONTAINS(Name__c, " "), MID( Name__c , FIND(" ", Name__c ), LEN(Name__c )), null)
Amol ChAmol Ch
Hi Lokeshwara
when i blank second string, this formula also not allow to me save the record. Please guide me.
Lokeswara ReddyLokeswara Reddy
What is the issue while saving the record? can you eloborate on the error message? do you have any validation rules on First Name standar field? 
Amol ChAmol Ch
When I enter Mahendra in Name field and Last Name Field and try to save the reocrd. It gives me error as in img. Their is no any validation rule on that field.

User-added image
Lokeswara ReddyLokeswara Reddy
Hi Amel,
Last name is Mandatory field on the Lead object, so you should always make usre you enter both first string and last string in the Name__c,

What I suggest is
1. If Name__c is filled only with one string then populate this on Last Name standar field and 
2. If Name__c is filled with both the string then have your current logic.

You can use
If( CONTAINS(Name__c, " "), LEFT( Name__c ,FIND(" ", Name__c )), Name__c )  - for Last Name
If( CONTAINS(Name__c, " "), MID( Name__c , FIND(" ", Name__c ), LEN(Name__c )), null) - for First Name

This will even retain the value in Standard Name field even if you null of Name__c value.
This was selected as the best answer