trigger trigMapFields on Lead (before update) {
Map<Id,String> leadStatus = new Map<Id,String>(); // Map of the converted Contact ID and the Lead Status
for(Lead lead : Trigger.new) {
if (lead.IsConverted) {
leadStatus.put(lead.ConvertedContactId,lead.Status);
}
}
List<Contact> conContacts = [select Id from Contact WHERE Contact.Id IN :leadStatus.keySet()];
for ( Contact c : conContacts) {
c.Type__c = leadStatus.get(c.Id);
}
update conContacts;
}
trigger trigMapFields on Lead (before update) {
Map<Id,String> leadStatus = new Map<Id,String>(); // Map of the converted Contact ID and the Lead Status
for(Lead lead : Trigger.new) {
if (lead.IsConverted) {
leadStatus.put(lead.ConvertedContactId,lead.Status);
}
}
List<Contact> conContacts = [select Id from Contact WHERE Contact.Id IN :leadStatus.keySet()];
for ( Contact c : conContacts) {
c.Type__c = leadStatus.get(c.Id);
}
update conContacts;
}
Refer below sample code.
Also refer below link for similar discussion.
https://developer.salesforce.com/forums/?id=906F00000008ve5IAA
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya
All Answers
Refer below sample code.
Also refer below link for similar discussion.
https://developer.salesforce.com/forums/?id=906F00000008ve5IAA
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya
Much Appreciated.
I have a custom field Home Phone in Lead and also in Contact. But after converting it should go to standard field Phone.
How this will work in code?
could you suggest.
Regards
Ajit
Map<Home_Phone,String> leadHome = new Map<Home_Phone,String>(); // Map of the converted Contact phone and the Lead phone
for(Lead lead : Trigger.new) {
if (lead.IsConverted) {
leadStatus.put(lead.ConvertedContactHome_Phone,lead.Home_Phone);
}
}
List<Contact> conContacts = [select Phone from Contact WHERE Contact.Home_Phone IN :leadHome.keySet()];
for ( Contact c : conContacts) {
c.Phone = leadHome.set(Home_Phone);
}
update conContacts;
}
is this the correct trigger? can anyone correct me if i am wrong?