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
Mark Dakyns 1Mark Dakyns 1 

Populate 'Record Name' field in custom object with fields from same custom object

I would like to populate the system Record Name field (Name) with a concatenation of two fields in the same custom object.
I have successfully written the following trigger as follows to do this:-
trigger MarkTest on Mark_Test__c (before insert) {
    for (Mark_Test__c obj: trigger.new){
        obj.Name = obj.Surname__c + ',' + obj.Forename__c;
    }
}
The only problem is I need to populate system field 'Name' with something before pressing [Save] as it is a required field.
Is there a way that I can suppress the 'Name' field or alternatively do something smart to solve this requirement?
Mark Dakyns 1Mark Dakyns 1
After some investigation I see this is not a unique request ... it also hasn't got any attention for the past 8 years!
https://success.salesforce.com/ideaView?id=08730000000Brs9AAC
Amit Singh 1Amit Singh 1
Mayank,

The workaround your problem is need to update records once record is saved into database but you need to put some values into the Name field.

For updating the name you do not need to write any you can create a worflow which will update the name field.

OR

If you do not want to put some value in the name field then you can create a VF page and override the new button of that Object with that VF pag.

If I was asked to complete the above task I must have been gone with the WFR.

Let me know where you find this solution.
Thanks!
Amit Singh
Mark Dakyns 1Mark Dakyns 1
Thanks Amit.
What would the advantage of using a workflow rather than a trigger be?