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

Status flag to determine if lead is being converted?

I've written an Account trigger to create/update a linked Contact record whenever an Account is created/updated.  I want to avoid a duplicate Contact being created when a Lead is converted.  Is there any Apex way to determine if you're in the middle of a Lead conversion so I can tell my trigger not to fire?

The Lead object has fields such as IsConverted, ConvertedContactId, ConvertedAccountId which may help you out.
Thanks for your reply.  My trigger is on the Account object though, so I can't read those fields.
Greg RohmanGreg Rohman

Any resolution to this? I have the same need/request. Thanks.


Maybe the solution is to have an "after insert" trigger at the contact level that simply checks if the contact being created already exists.  You could validate that the phone number and/or email address don't already exist for another contact associated with the same account.

This would not only prevent dupe contacts from lead conversion, it would also prevent dupe contacts being entered in manually.

Of course, you will have to test if this trigger fires when a lead is converted to an account, contact and (optional) opportunity.