+ Start a Discussion
Aliaksei RazumauAliaksei Razumau 

How to relate contact / lead objects to a custom object.

I want to use access codes for specific events. I have a custom object called "Event Codes" with only one primary field which represents access code itself (text symbols only with length < 16, each code is unique). I manually add up new codes to an object. Some contacts and leads have text field with access code and it's one of the values of a custom object mentioned above. I use an integration with 3rd party, so that some contacts and leads have this field populated automatically with access code (text representation).

How can I relate contact / lead with my custom object based on access code? How can I relate already existing records?

I believe "Event codes" object should be a master while lead / contact are children. But I can't create master detail relationship at contact / lead object (have no such option).
I think you'll have to create a lookup field on Lead and Contact, with the target object of 'Event Code'.  
In order to relate the existing records you'll need to write some Apex code that finds the Event Code record matching the text field on the Lead/Contact record and populate the lookup with the record id.
You can then use this code from a trigger to populate the lookup when a new Contact/Lead is inserted with the text field populated.
This does pre-suppose that the event record exists though - you may need to create these as part of the apex code too.
Smita HodiggeriSmita Hodiggeri
Thanks for this bob, I was blank for a moment how do I make my custom object appear on lead object's "related list"
I created lookup on my custom object with target object as lead(parent) , my coj now appears on lead parent obj