1

So I have a custom object that have lookup fields for Leads and Contacts. When a user converts a Lead to a Contact, how would I make it so that custom object's Lead value propagates to the Contact field as well?

2
  • so starting condition is lead L is parent of custom object X; then lead is converted to a contact C and you want custom object X to now have Contact C as its new parent? Commented Jan 21, 2015 at 19:00
  • Yes. Custom object X has lookup fields for both Lead and Contact. When Lead conversion happens, I want that lookup field for Lead to also propagate to Contact. Commented Jan 22, 2015 at 18:15

1 Answer 1

1

You will need to solve this with an after update trigger on Lead. Something like this:

trigger LeadConversionCleanup on Lead (after update) { List<CustomObj__c> customObjUpdList = new List<CustomObj__c> (); // Get only converted leads in the trigger list plus all children for (Lead l : [select id, ConvertedContactId, (select id from customObj__r) from Lead where isConverted = true and id IN : Trigger.new]) for (CustomObj__c c : l.customObj__r) // could be 0+ children // re-point CustomObj to converted contact customObjUpdList.add(new CustomObj__c (id = c.id, contact__c = l.ConvertedContactId, lead__c = null)); update customObjUpdList; } 

Code presumes that CustomObject__c has two lookup fields: Lead__c and Contact__c

Above was typed in and may have typos

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.