Friday, April 19, 2013

One to One Relationship in Salesforce


We all know about the 1-M && M-M relationship(using junction Object) in salesforce.
Some times we may need 1-1 relationship among two objects.
but Unfortunately Salesforce doesnot allow any direct methodolgy to build 1-1 relationship

We can achieve the same by workflow or trigger. But workflow is more flexible & the easier way

Steps
-------
Say Two Objects OBJECT-A and OBJECT-B

1- create a look up field in one object
    say in OBJECT-A, there is a lookup to OBJECT-B
    field Name= obj-B (say)

2- Create another textfield at same Object with unique property (used to hold same obj-B field value)
     fieldName= unique_Obj-B (say)

3- Define a workFlow Rule /Trigger to  Update the custom "unique_Obj-B" field with the value of the associated OBJECT-B ID.(i.e the field value of "obj-B")

Now we have done with 1-1 Relationship
When we try to add a second same OBJECT-B to the OBJECT-A, the "unique" constraint in OBJECT-A (field "unique_Obj-B")would be violated and an error would be thrown.....

7 comments:

  1. This is Nice Post, It is quite helpful .

    ReplyDelete
  2. Nice blog.Thanks for sharing useful information on Sales force.

    ReplyDelete
  3. nice, is there any live example with image, how to use workflows

    ReplyDelete
  4. This is helpful but what would be condition for workflow rule..when it will going to fire?Please help me out

    ReplyDelete
    Replies
    1. you can put condition like
      1- ID != null
      OR
      2- the lookup field != NUll

      Delete
  5. you can put condition like
    1- ID != null
    OR
    2- the lookup field != NUll

    ReplyDelete