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
Janno RipJanno Rip 

Custom Object Conversion - Get Name and Company

Hello everyone,

I have a custom object called "Leadevents__c" that can be attached to Leads and Accounts. In the screenshot it is attached  to Lead: 
User-added image
After conversion it will get attached to an account. We have an apex class in place that provides this:
User-added image
However I lose the contact on my way from Lead to Account. What I would need is the following result:
User-added image

The challenge is that the apex class provinding said usability is over 10 years old and not mine. I was able (at least I think so) to figure out the code responsable:

User-added image


I added "Kontakt__c" so that I could refer to "le.Kontakt__c" and give it a value. Now I have a fix contact ID in there which actually works. When I convert a lead, this contact ID is attached to the "leadevent__c". Obviously I need a dynamic verison. Is anyone able to review this code and tell me if this is the right place and what I would need to achieve this?

Thanks guys!
Best Answer chosen by Janno Rip
Khan AnasKhan Anas (Salesforce Developers) 
Hi Janno,

Greetings to you!

Please use below line of code:
 
le.Kontakt__c = leadNew.get(le.Lead__c).ConvertedContactId;

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Janno,

Greetings to you!

Please use below line of code:
 
le.Kontakt__c = leadNew.get(le.Lead__c).ConvertedContactId;

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Janno RipJanno Rip

Hallo Khan,

thanks for your insight. While I can save my apex class without getting any error messges, I get an error during the conversion process:

LeadConvert: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Class.AK_LeadEvents.leadMoveEvents: line 19, column 1 Trigger.LeadConvert: line 5, column 1

line 19, column 1 is the new part:   le.Kontakt__c = leadNew.get(le.Lead__c).ConvertedContactId;

here is the code of the trigger:

User-added image
 

Janno RipJanno Rip
Me again, 

I fixed it myself by classic try and error. The trick was to "delete" / "deactivate" the following:

User-added image
le.Lead__c = null needs to be gone