Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  • I have an object in which there are two fields i.e Phone no. & email.
  • The combination of these fields should be unique
  • Right now I can create just one unique field But I want their composite to work like a unique field.

I know that I can create composite key in SQL but I dont know how to achieve this in salesforce.

share|improve this question
    
You have accepted an answer that is more or less incorrect. The community would be better served by changing your accepted answer. Did you implement a trigger? Did you try the WFR approach? – Adrian Larson Mar 10 at 20:38
up vote -3 down vote accepted

To achieve this you need to have following things in mind:

  • We can not create composite key in salesforce.
  • There is already an Idea posted about this.
  • You can achieve this by writing a trigger in which you can query old records and check unique behaviour as per your need.

You can ask me if you have any doubt.

share|improve this answer
    
Can we use formula field to achieve this ? – GrV Aneja Feb 12 at 20:11
1  
we can not create formula field unique. – ashishcloud Feb 12 at 20:11
1  
Ok Thanks Ashish for your prompt response... – GrV Aneja Feb 12 at 20:12
2  
If you are going to mention that there is an Idea posted, you should link to it... – Adrian Larson Feb 12 at 20:19
1  
@GrVAneja you can use workflows and do not need code. Look at Adrian's answer – Samuel De Rycke Feb 15 at 7:50

You can create a unique composite by concatenating values. The steps would be:

  1. Create a unique Text field.
  2. Create a Workflow Field Update to concatenate the fields whose composite you want to be unique and populate into the above field.
  3. Create a Workflow Rule that uses the field update above if any of the source fields have changed.
share|improve this answer
    
This process works well. If you mark the text field as an external key, it will enforce uniqueness and be indexed. In our org, we separate our values with an underscore. For example, ClientCode_EventCode_LocationCode. – Christian Anderson Feb 12 at 22:52
    
@ChristianAnderson Indeed, there are many concatenation schemes. Dashes and underscores are probably the most common. Thanks for the feedback! – Adrian Larson Feb 12 at 23:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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