You need to sign in to do that
Don't have an account?
Zimmer
Associating a Custom Object with a Contact on Lead Conversion
I have a custom object that stores Marketing Activity. It can be associated with either a Lead or a Contact. When a lead that has associated object is converted I would like to update the custom record to reflect the new ContactId so that the activity will be preserved in the related list.
Does anybody have any pointers on how to do this?
Thanks,
Phil
Hi Phil
One possibilty would be to have after insert trigger on Contact that searches the lead object for a field 'ConvertedContactId' that matches the new contactId. When you've found one that matches it's simply a case of removing the lead id on your custom object and putting in the contact id (I'm assuming they're seperate fields...).
Thanks
Steve
Pretty sure the best way is a lead trigger after update that checks for IsConverted=True and ConvertedContactId.
Is there a tutorial on this task?
My organization just start using Salesforce and the first Custom object i configured I already need to do this.
This must be very common type of request.
http://wiki.developerforce.com/index.php/Apex_Day_Lab_Exercises
Did you ever find a way to do this? We are needing this as well and I can't figure out how to write my trigger for it.
I found a wonderful resource that was able to help me with this. Here is the code I'm using:
trigger UpdateOHObject_Trigger on Lead (after update) {
Map<Id, Lead> leadMap = new Map<Id,Lead>();
Lead parent;
for (Integer i = 0; i < Trigger.new.size(); i++){
if (Trigger.new[i].IsConverted == true && Trigger.old[i].isConverted == false) {
leadMap.put( Trigger.new[i].Id, Trigger.new[i]);
}
}
if( leadMap.size() > 0 ) {
Set<Id> leadIds = leadMap.keySet();
List<Opportunity_Headings__c> allChildren =
[select Id, Opportunity__c, Account__c, Lead__c from Opportunity_Headings__c where lead__c in :leadIds];
System.debug(allChildren);
for ( Opportunity_Headings__c child : allChildren ) {
if ( leadMap.containsKey( child.Lead__c ) ) {
// lookup the parent lead
parent = leadMap.get( child.Lead__c );
// update the fields on the child object
child.opportunity__c = parent.ConvertedOpportunityId;
child.account__c = parent.ConvertedAccountId;
}
}
System.debug(allChildren);
//try {
update allChildren;
// } catch( Exception e ) {
// could put something here to notify on error
// otherwise it fails silently
// }
}
}
Thanks again Robert!!