Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

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

1 Answer

0 votes
by (32.1k points)
edited by

If you are looking for a more simpler design, then you might want to use a static mapper class for this. Here is a pseudo code which might help you solve this problem:

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 you could convert the lead to contact prior to usage and get the resulting contact ID. You can do this by the following code:

CustomMapper.leadToContact(myOldLead, myContactID);

So, now if you perform a conversion, right after performing the custom mapping with an update, it will seem like an instant update to the users. I hope my answer was satisfactory enough.

Enroll in our Best Salesforce Course to get a professional certification!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...