This a more complex point that it looks like.
First, as in SFDC leads and contacts are 2 separate objects, your custom object needs obviously to be attached to both of them in SFDC with 2 separate lookup field.
But the hard point is that once you have enabled the 2 relationships, you cannot create 1 custom object in Marketo that maps on the 2 relationships, and that is NOT possible, as both objects would have the same name in Marketo.
This issue has been in my mind for quite a while and I eventually entered the idea here: Enable smart mapping of SFDC Custom object linked to lead and contact or lead and account
@Grégoire We are trying to build a custom flow for achieving this.
- We create a custom Salesforce Object A and connect it with Lead. Similarly, we create a custom Salesforce Object B and connect it with Contact.
- When a lead which has data in Object A,is converted into a contact in Salesforce, we update the data in Object B. This way we make sure we do not lose any data.
- In our velocity scripting code, where we have to fetch the data from custom Salesforce objects, we add a check for Lead & Contact.
If the record in Marketo is a Lead, we fetch the data from Object A and print it in the email.
If the record in Marketo is a Contact, we fetch the data from Object B and print it in the email.
This should work and is, IMHO, the only way to get it right, taking into account the current limitations. Well done.