Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map Custom fields of Leads in Salesforce

I wanted to map custom fields of lead to map with custom field of contact' when converted using binding.convertLead().

It should replicate the behaviour what we are manually doing from UI when custom fields of Lead are mapped with contact (Navigate to SetUp->Customize->Leads->Fields then in Lead Custom Fields & Relationships section Map Lead Fields button.)

I have the C# code to convert a lead into contact. However I need to map the custom fields of lead to custom fields of contact.

Like for e.g:

1) Lead.Newsletter__c (Custom field of check box type in lead)

2) Contact.Newsletter__c (Custom field of check box type in contact)

3) Now, if Lead.Newsletter__c is checked then when I convert any lead to contact, then Contact.Newsletter__c should be checked automatically.

I am able to fetch all the custom fields by using describeSObjects of Partener WSDL proxy class, but still unable to located where the changes should be made

like image 632
Ashish Upadhyay Avatar asked Jun 05 '14 10:06

Ashish Upadhyay


People also ask

What is map custom lead fields in Salesforce?

Required Editions and User Permissions If you set up custom lead fields, you specify how that custom information converts to custom fields in accounts, contacts, and opportunities. From the object management settings for leads, go to the fields section, then click Map Lead Fields.

Can we map custom fields from leads to account and opportunity at the same time?

For each custom lead field, choose a custom account, contact, or opportunity field into which you want the information inserted when you convert a lead. In Lightning Experience, a custom lead field can map to account, contact, and opportunity fields at the same time. 3. Save your work.


1 Answers

If you want a simple design, essentially I would do it in a static mapper class. We definitely need more information to help you, but short of that, here is some psuedocode (not production code) that should be a sufficient design pattern.

public static class CustomMapper {     public static void leadToContact(Lead lead, ID contactID)     {         var contact = new Contact(contactID);         ///do mapping here         ///eg         ///returnval.Newsletter__c = Lead.Newsletter__c;          contact.save();     } } 

then for the usage:

//convert the lead to a contact prior to usage here, and get the resulting contact id CustomMapper.leadToContact(myOldLead, myContactID); 

If you perform the conversion, then immediately after perform the custom mapping with an update, then it will seem instantaneous to the users anyways. Without more information, this is the best, generic design pattern that I could recommend.

like image 172
HBomb Avatar answered Sep 20 '22 13:09

HBomb