9

I have created a new custom object for which I have no use for a record name. Is there any way which I am able to remove name from the list of standard fields?

If I am required to name the object, I would prefer it that this name be created automatically based on values populated from other fields, not simply an auto-number or text?

Is there some kind of work-around for this?

  • 3
    What we really need is Salesforce to allow overwriting an auto-numbered Name with a String! :-) – bigassforce May 16 '14 at 15:02
14

You can do this without throwing away the native page layouts. Assuming your object is Person__c:

  1. Override the New button with a redirector like this to set a sensible default value:

    <apex:page
        standardController="Person__c"
        action="{!URLFOR($Action.Person__c.New, null, ['Name'='Derp'], true)}"
    />
    
  2. Create a Workflow Rule that sets the actual intended value (eg from other fields)

    workflow-details

This displays a non-empty Name that is overwritten by a workflow rule when saved. It's currently the only way to keep the native page layouts while not requiring the user to enter a non-empty Name.

Note you can default the Name using Predefined Field Values on a Create Record Publisher Action.

As you noted, you can remove the Name from Page Layout only if it is an auto-number field.

| improve this answer | |
  • When are you setting the workflow rule to run, though? When a new record is created or updated? – toolshed May 16 '14 at 15:45
  • "Evaluate the rule when a record is created, and every time it’s edited." @Addikt – bigassforce May 16 '14 at 15:58
  • This is the pattern we've used for years, and it works great. (You can even go the extra mile and use the "$Action.Person__c.New" technique in URLFOR). The problem is that this whole pattern fails badly inside of the Salesforce1 mobile app. We're still experimenting with the best solution for this problem. – Matt Welch May 17 '14 at 16:53
  • 2
    @user320 Sorry. Was away for most of the weekend. URLFOR has a fourth parameter which, when set to true, will skip the override, and take you straight to the "new" page for the object. – Matt Welch May 19 '14 at 16:05
  • 1
    Very forthcoming addition @MattWelch - thanks! I've tested this works OK and incorporated it :-) – bigassforce May 19 '14 at 16:11
3

This is a great example of when to use Flow. Just create a Flow to gather all the data from which the name can be constructed. The Flow will create the record. You will need give users a link or tab to run the Flow. You probably want to override the "new" button for that object to run the Flow instead. Very little code required, easy to maintain!

| improve this answer | |
  • 1
    Nice angle on flow, love this! – bigassforce Oct 20 '14 at 11:39
2

"Is it possible to create a SF object without a name" - No each sObject have to have value in this field

"or automatically populate it based on other field values?" - It is possible only by Visual force page. You just need to override standard save method and set name using apex logic.

| improve this answer | |
  • Yes, it's possible to insert a custom SObject record without a name. The Name defaults to its Record ID. Try it in Apex. – Scott Pelak Oct 23 '19 at 19:48
  • And there are other ways to populate the Name field upon DML such as Triggers, Workflow, Process Builder. And then one can also create records with auto-populated Name via Quick Actions and Flows and Lightning Components + Visualforce – Scott Pelak Oct 23 '19 at 19:50
  • 1
    Hi @ScottPelak I am full of respect that you find time to comment 5 year old answer :) Since you did it, I feel obliged to address your comments ;) I am not even sure how it worked back then, but I think it was only way to remove Name field from layout for user. You are right you can not populate this field in backend and it will be populated in backend. but still you would have to set meaningful name with apex/workflow etc. – Artur Kępczyński Oct 24 '19 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.