function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lauraecilauraeci 

Passing Custom Field Data from the Lead to the Contact on Convert

I am trying to get this trigger working where after I have converted a Lead to a contact, I want to save data from the Lead.Secondary_Email__c to the Contact.Secondary_Email__c.

 

I feel like I'm close but I can't get a contact from the Lead...  Any help would be appreciated!

 

trigger onLeadConverts on Lead (before update){

for (Lead l: trigger.new){
if(l.isconverted==TRUE){
// l.ConvertedContactId;

// Contact c = new Contact(id = l.ConvertedContactId);
//Contact c = Contact(id = l.ConvertedContactId);

 

// l.ContactId is not recognized?? How do I get the ContactID from the Lead?
System.assert(l.ContactId);

Contact[] c = [select Id from Contact where Id = l.ContactId];


c.Secondary_Email__c = l.Secondary_Email__c;
}
}
}

Best Answer chosen by Admin (Salesforce Developers) 
matermortsmatermorts

Why doesn't it work just to setup a standard field mapping from the Lead object?

All Answers

matermortsmatermorts

Why doesn't it work just to setup a standard field mapping from the Lead object?

This was selected as the best answer
lauraecilauraeci

Thanks, I was able to get the trigger to work but a standard field mapping would be preferred because its less maintence.  I'll try that!