+ Start a Discussion
NJDeveloper019NJDeveloper019 

Object record Name as formula

I have a custom object named Consultant that holds contact information for consultants of our company.  FirstName and LastName are the two fields within this custom object that represent the consultants name.  My issue, is that when running a lookup to this Consultant object, the record name is the value that comes up.  I can add fields to the lookup so you could see the FirstName and LastName but there is still a problem.  The object that is related to Consultant, will only show the record name in the lookup field in the record.  I want to make my record name for Consultant a formula field that is a concatenation of First Name and LastName.  The standard object Contact has a setup like this and I want to replicate it.  I don't see how to handle this if it's even possible.  Can this be done and if so, how?

 

Thanks,

 

Ralph

Best Answer chosen by Admin (Salesforce Developers) 
CaptainObviousCaptainObvious

The record name cannot be a formula or have a default value. When you set up the Object, did you select the record name as a text or auto number?

 

This workaround will not work if it's an auto-number:

 

Create a Formula field on the Consultant object with the formula: First_Name__c &" "& Last_Name__c call it "Concatenated Name", for example.

 

Create a workflow rule to update the record name: for the Rule Criteria, enter Name != Concatenated_Name__c for Evaluation Criteria, set it to Every time a record is created or edited.

 

For the field update, set Field to Update: Consultant Name and use the Formula Value: Concatenated_Name__c

 

With this workflow in place, you could enter any information into the record name to get around the field requirement, and workflow will update it accordingly. Seems silly, but it just may work.

All Answers

CaptainObviousCaptainObvious

The record name cannot be a formula or have a default value. When you set up the Object, did you select the record name as a text or auto number?

 

This workaround will not work if it's an auto-number:

 

Create a Formula field on the Consultant object with the formula: First_Name__c &" "& Last_Name__c call it "Concatenated Name", for example.

 

Create a workflow rule to update the record name: for the Rule Criteria, enter Name != Concatenated_Name__c for Evaluation Criteria, set it to Every time a record is created or edited.

 

For the field update, set Field to Update: Consultant Name and use the Formula Value: Concatenated_Name__c

 

With this workflow in place, you could enter any information into the record name to get around the field requirement, and workflow will update it accordingly. Seems silly, but it just may work.

This was selected as the best answer
NJDeveloper019NJDeveloper019
No, I appreciate the help.  I had thought of that idea but I was hoping there would be a less hacky way to handle this.  I will do that though.  Thanks.
dgb511dgb511

Your solution for the above post was brilliant, but if the record hasn't been manually edited the workflow rule never gets triggered so you end up with some records displaying the concatenated version and some not.  I'm hoping you also have a solution to this problem.

 

Thanks for your help with our problems. 

 

dgb511

dave@reln.com

CaptainObviousCaptainObvious

Here's where the Excel Connector comes in handy...

As you've noticed, workflow is not retro-active, so any records created/edited prior to the workflow will not display the concatenated version.

Using the Excel Connector, select your object and query all the records with a Created Date less than the date workflow was activated (the Record ID, Record Name, and Concatenated Name fields will suffice).

Select the Record Name cells on the worksheet and Update Selected Cells from the excel connector menu.

It may take a few minutes depending on the number of records you have, but it's a lot easier than editing each individual record to trigger workflow!

Note: To verify that the update was successful, refresh the query by selecting Query Table Data after you run the update.

Message Edited by CaptainObvious on 09-16-2009 09:33 AM
dgb511dgb511

Thanks, and you're right it's a lot easier than manual editing hundreds of records.

 

Rob BaillieRob Baillie
This works, but it does require people to enter data into the Name field that will then immediately get wiped out.  Is there a better solution out there yet?
Ruwantha  LankathilakaRuwantha Lankathilaka
If you do not want to enter the name you can change the name field type to auto number and the write a trigger after upsert to concat the name field
Rachel LinderRachel Linder
I have a custom object called "Vendor Part Numbers" that has autnumber currently for the record name. The object has a field called Part Number Key (which is a concatenation of two other fields). Is it possible to use this field for the Record Name instead of the autnumber? What steps would i need to take to convert my current object over? Or would it be best to create new custom object and then dump the other records in to the new object?
Michael SamwiseMichael Samwise
Ruwanthalk, I'm not sure how that would work. At least in my experiments with workflow rules I have not been able to update the autonumber field with a text expression based on a formula in a custom field. The auto increment Name is not offered in the workflow rule action dialog. The motive here is to have something like the text Name field for the object, but not to make the user enter something in the Name field which is then immediately overwritten by the workflow rule action. I was hoping your suggestion would work and that by setting the Name field to auto increment, it's removed from the data entry flow, and yet can be populated by a text value via rule. You said trigger... I tried via rule, is that the difference?
Mark Dakyns 1Mark Dakyns 1
Has there been any 'smart' solution to Ralph's original request? I have the same issue as I need the Record Name to have more meaning then an auto numbered formatted field. I wrote the following trigger to populate the field, but it still needs to be populated in the input screen:-
trigger MarkTest on Mark_Test__c (before insert) {
    for (Mark_Test__c obj: trigger.new){
        string initial = obj.Forename__c.left(1);
        obj.Name = obj.Surname__c + ', ' + initial;
    }
}
The issue of not being able to suppress the Record Name field or make it read-only is still a problem as there is nothing stopping someone changing the Name field when editing the record.

Frustrating ...
sumit kumar 276sumit kumar 276
Hey @Mark -  were u able to fix your above issue..?? ?  I think we do not have other way arround for this issue.. i m also having sort of same use case .. where i dont want to keep.. Name - (std fiied)as auto Number and also do not want to make it available for user to..INPUT any data in Name field.. just wan to.. before insert.. set some value like-- Name = ' xyz inc.' (default value)..and then W.F will take care to Update it to meaning full value based on requiremnet.

i tried seeting default value using W.F Rule... FAILED
I wrote Trigger to set default value for Name field (as same as your trigger.. given above)..... FIALED

can any1 help me on this... any idea..?
Mark Dakyns 1Mark Dakyns 1
Sorry Sumit but I didn't find a way around this issue.
EGA FuturaEGA Futura
I have carefully read the whole thread and I also have to solve this same problem.
Has anyone found an efficient solution to this?
EGA FuturaEGA Futura
In this image the desired behavior is shown: http://media.egafutura.com/ed003059cbc0
sunilSecond singhSecondsunilSecond singhSecond
Anybody got any solution or work around for the above problem ? 
Steven FischerSteven Fischer
What led me here: Users cuoldn't search records by contact name or date on mobile app, only by record name. When using an iterator, this is wildly inconvenient. "T-1150" doesn't tell us anything about what is inside the record.

CaptainObvious' post above inspired this. Because the Flow builder is relatively new, and I had to write this out for our IT Knowledge base anyway, I figured I'd share it here in case it helps someone.

This does still require anything to be typed into the field to save a record, but...

I got this to work for me today using the a Flow. I set the Name field on my object to a text(80) field type. I stopped trying to make it auto-apply the naming convention I wanted upon creation of the record and instead used a Flow to automatically update the name upon Create (and Update, but that's optional)
I wanted the record name to populate the values from the Contact and Date fields.

In Setup > Home > Process Automation > Flows - click New Flow.
Then select " Record-Triggered Flow"
I selected the object I was working on, in this case a Trespass Tracker.
Optimize the flow for: "Actions and Related Records
Click Done then press the + sign under "Run Immediately"
Scroll downa dn select Update Records.
Name it as you see fit...
Choose the field: Name
In Value, you can't select multiple things at once to add them together all at once. You need to find the field you want to reference, copy and paste it into a document, X out that option and then select the other field you are wanting to add, and repeat this as many times as you see fit.

For example, I clicked Value, then $Record then Contact__r then found Full Name which looks like this:  {!$Record.Contact__r.Full_Name__c}
I copied that and then X'ed it out. I then did $Record again and clicked $Date_of_Trespass__c which gave me: {!$Record.Date_of_Trespass__c}
In a word doc, I put {!$Record.Contact__r.Full_Name__c} - {!$Record.Date_of_Trespass__c} together and copied and pasted that whole thing into the Value field. (Yes it let me add the spaces and the - in between)

Now my records all say "John Doe - April 5, 2022" for example.

I chose to have this Flow trigger when a record is created OR updated. I exported all existing records and then ran an update through Data Loader with a 1 (anything different than it was will work) in the Name field. Doing so applied the new naming convention to all past records as well. 

I hope this is helpful to someone!