+ Start a Discussion
KamleshKamlesh 

One-to-one relationship

Hi,

 

How can i create one-to-one relationship between two custom objects in salesforce.com. 

 

Example: I have two custom objects having following details:

 

1) Employee (Name, PanCardNo)

2)PanCard(PanCardNo Name_on_card)

 

I have gone through documents of salesforce, but i can able to find out only lookup (One-to-many raltionship) and master-detail relationship(many-to-many relationship).

 

Is there any way to create one-to-one relationship??

 

Regards

kamlesh kumar

werewolfwerewolf
First question: if it's one-to-one, why not collapse all the fields into the Employee object?  It doesn't seem like you need a relationship there.
infoweldernickinfoweldernick
Agreed - if it's ALWAYS a one-to-one relationship, why do you need a custom object?
Thomas StrohThomas Stroh

The last couple of posts were looking for reasoning behind the one-to-one relationship.

 

I have created a custom object "Source", which simply stores a "Unique Identifier" or GUID that is used from external systems. The other objects (i.e. Contacts, Accounts, Cases, othehr custom objects) have a Lookup relationship to this "Source". This is a scenario in which I would want to maintain a one-to-one relationship.

 

Yes, I could create a "Source" field on each object, but then this would require me searching each object that might contain the source field. And when working with the the API, we have to deal with the governors (limitations) in how we can query into the system.

 

So, hopefully trying to keep this conversation going to see if there are any ideas out there?

 

Thanks

werewolfwerewolf
Yes, but if Source is one-to-one with, say, Contact, then why create a separate Source object?  Why not just store that GUID on Contact and set your other objects to look up to Contact?
Thomas StrohThomas Stroh

Sorry, maybe it didn't fully explain the condition. I have multiple objects (i.e. Contact, Account, Case, etc.) that have a lookup to "Source". I want to ensure that one Source can only be assigned to one Contact ... or is only assigned to one Account.

 

I hope that explains it better.

werewolfwerewolf
Then you can use an Apex trigger to enforce that.
infoweldernickinfoweldernick
If you create the field as an external id, you can also ensure uniqueness in that field.  That will also allow you to do upserts to that object based on the external id and circumvent any searches for the record through the API.
Alan.MarcusAlan.Marcus

This is a real let-down for me.  I know it is requested on Ideas. 

 

I've done it before using a lookup and related list, use roll up summary field and a validation rule saying that roll up summary field can't go above the value "1".  Does anyone have a better solution?

 

It would be great to find a native solution.  I know it can be done in Apex.  Is this the best solution using native funcitonality?

 

 

Sai Ram ASai Ram A
Create a lookup field on the child
Create a unique field on the child, and hide this field from all page-layouts
Write a workflow, for any change of the lookup field, to copy that value from the lookup field into the unique field

This process has many overheads:
Extra field is required
Unique criteria is utilized (we only get 3 unique fields per object)
Workflow is used


Another way to do is... create a master detail relationship and than on master create a roll up summary field of child with count. then you write validation on rule rollup summary field to check for >1 .. so it will give you error if it has more than one record for same master detail relation values..

one to one created...
 
pranav prashantpranav prashant
refer this article
http://one-to-one-salesforce.blogspot.in/
Naidu SagviNaidu Sagvi
Hi SriRam,
    Suppose we lookup relation ship b/w two objects,then what type rule and evalution criteria we need to write....
if u know can u help me....
Thanks,
Naidu SagviNaidu Sagvi

Hi SriRam,
    Suppose we have lookup relation ship b/w two objects,then what type of rule and evalution criteria we need to write....
if u know can u help me....
Thanks,
Marissa RobinsonMarissa Robinson
Hello, 

We are trying to make opportunities a one-to-one relationship with contracts so that our reporting and workflows are more simplified. For example, we currently can not create a workflow that when an opportunity stage is set to "Closed Won" we would like our contracts to automatically activate. When we go to create this workflow, and set it on opporutnity (since thats where the trigger field is located) only opportunity and accounts is listed as an option. 

Any ideas on how to make the opportunity to contract one-to-one so that we can have not only 1 contract related to 1 opportunity, but also to achieve the workflow listed above? 

Any recommendations would be appreciated!
Gajanan KadamGajanan Kadam
Hello Marissa,

Step1: You can create Master details relation between on contract with Name as Opportunity.
Step2: Make Contract name as Unique by editing Contract name field.
Step3: Create a roll-up summary field on an opportunity with Summary Type as count.
Step4: Write validation rule on the roll-up summary field with count > 1 then through error.

Then you to make the opportunity to contract one-to-one so that we can have not only 1 contract related to 1 opportunity.

Thanks