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
Naperville JimNaperville Jim 

lead.convertedOpportunityId not set yet in opp after insert trigger

I have an opportunity after insert trigger relying on the value being set in lead.convertedOpportunityId during convert lead processing. Its mission is to grab some custom fields out of the lead that generated it and hook up additional opportunity contact roles. The trigger was working fine a few weeks ago, but I now see that this query in the opportunity trigger:

 

Select my_custom_col__c from lead where convertedOpportunityId = opp.id

 

Is finding no rows. I realize the order of database operations during convert lead will make a difference, but this used to work.

 

Can anyone confirm what I’m reporting here is the expected bbehavior? If so, did something change in recent history to make it so and are the expectations I can rely on during convert lead documented some place?

Naperville JimNaperville Jim

I could not find definitive information on the order of processing during convertLead. I went ahead and moved the work I was doing to a lead after update trigger. There I check for convertedOpportunityId to be non-null when it used to be null. In that situation I create a couple additional OpportunityContactRole objects for that opportunity using data from custom fields in the lead.

 

This new approach appears to work, but, of course, it still relies on the order things happen during the convertLead processing. In retrospect, however, this seems like an approach more likely not to break.

 

I also want to mention that I discovered this issue because one of my tests deployed in an enterprise account stopped working without my having changed anything. So, I know it once worked for sure or it never would have been allowed into production.