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?
- 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?cropredy– cropredy2015-01-21 19:00:39 +00:00Commented 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.dl8– dl82015-01-22 18:15:00 +00:00Commented Jan 22, 2015 at 18:15
Add a comment |
1 Answer
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