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
RiothamusRiothamus 

Making Name field unique

Few questions:

I have a class with 'State' and 'Number'. The combination should be unique, and should be the Name field for the table. I'm hitting some road blocks that I suspect are built-in limitations of SF:

 

  1. Is there a way to make the Name Field a formula? If there is, I haven't found it.
  2. Is there a way to require the Name Field to be unique?
  3. Is there a way to make any Formula Field unique?

One work-around would be using auto-increment for the Name, but this will show up on Lookup Fields, and that's a deal killer. Any suggestions?

Another would be a Trigger that sets the Name before the district is saved and checks for uniqueness. This seems a lot of work for what should be something easy, but I could do it.

 

Is there an elegant approach. What have people tried?

Best Answer chosen by Admin (Salesforce Developers) 
Noam.dganiNoam.dgani

Hi Riothamus

 

you can do the following:

 

1. create a text field (dont put it on the page layout) and set it as unique.

2. Create a workflow on create/edit of the table (edit of the relevant fields if you want to be efficient) that concatenates the two fields you want into the created text field AND to the record name.

 

this way you get the value you want in the name of the record + uniqueness.

 

hope this helps - if it does, please mark as solution.

All Answers

Noam.dganiNoam.dgani

Hi Riothamus

 

you can do the following:

 

1. create a text field (dont put it on the page layout) and set it as unique.

2. Create a workflow on create/edit of the table (edit of the relevant fields if you want to be efficient) that concatenates the two fields you want into the created text field AND to the record name.

 

this way you get the value you want in the name of the record + uniqueness.

 

hope this helps - if it does, please mark as solution.

This was selected as the best answer
linghongyong12@163.comlinghongyong12@163.com

When you set up a Text field,you will see:

External ID      checkbox(null)

Set this field as the unique record identifier from an external system

You can do like this:

External ID     checkbox(true)Set this field as the unique record identifier from an external system

Then this field is unique,you can try.

Patrick Maxwell 2Patrick Maxwell 2
I know this question is super old, but I was able to accomplish using the VLOOKUP formula and wanted to share for anyone that may want an easier solution.  VLOOKUP is only available for Validation Rules as far as I know, but this worked for me on a custom object call Territory.

(ISNEW() || ISCHANGED(Name)) && VLOOKUP( $ObjectType.Territory__c.Fields.Name, $ObjectType.Territory__c.Fields.Name , Name) = Name