Question
I’m working on a project where I need to customize the standard lead conversion process. Triggers during lead conversion have always been tricky in past projects, so I want to ensure I fully understand the exact order of execution before designing my solution. However, after searching extensively, I haven’t found a clear and detailed breakdown.
Does anyone know the precise order in which triggers fire for all objects involved in lead conversion? Specifically, I am not asking about general trigger execution but rather how triggers behave across the Lead, Account, Contact, and Opportunity objects during the conversion process. Based on my understanding, the execution might look something like this:
Lead Before Update Triggers (isConverted = false, convertedAccountId = null, convertedContactId = null, convertedOpportunityId = null)
Account Before Insert Triggers (only if a new account is created, not fired if merged with an existing account)
Account After Insert Triggers (only if a new account is created, not fired if merged with an existing account)
Contact Before Insert Triggers (only if a new contact is created, not fired if merged with an existing contact)
Contact After Insert Triggers (only if a new contact is created, not fired if merged with an existing contact)
Opportunity Before Insert Triggers (only if an opportunity is created, OpportunityContactRoles = null)
Opportunity After Insert Triggers (only if an opportunity is created, OpportunityContactRoles = convertedContactId)
Lead After Update Triggers (isConverted = true, convertedAccountId = XXX, convertedContactId = XXX, convertedOpportunityId = XXX)Is this order correct? Are there any special considerations I need to be aware of?
Answer
The usual order of execution outlined in Salesforce Documentation still applies to lead conversion, but there are some special considerations.
One of the key factors is whether “Enforce Validation and Triggers on Lead Conversion” is enabled in Setup > Lead Settings.
If this setting is enabled, before triggers and validation rules will fire during lead conversion. However, this setting is not enabled by default in older orgs (pre-2008), and Salesforce support may need to enable it manually.
If this setting is disabled, before triggers do not fire, but after triggers still fire.
A good place to handle custom lead conversion logic is in the Lead After Update trigger. Here, you can check if the lead was just converted using:
if (Trigger.isUpdate && Trigger.new[0].IsConverted && !Trigger.oldMap.get(Trigger.new[0].Id).IsConverted) {
// Custom lead conversion logic
}At this point, convertedAccountId, convertedContactId, and convertedOpportunityId are available, making it the best place to reparent related records from the lead to the newly created account or contact.
Observed Trigger Execution Order
Through debug logs, we can confirm the order of execution during lead conversion when “Enforce Validation and Triggers on Lead Conversion” is enabled:
1. Account Custom Field Mappings
2. Account Before Insert (only if a new account is created)
3. Account After Insert
4. Contact Custom Field Mappings
5. Contact Before Insert (only if a new contact is created)
6. Contact After Insert
7. Opportunity Field Mappings
8. Opportunity Before Insert (only if an opportunity is created)
9. Opportunity After Insert (OpportunityContactRoles not available yet)
10. Lead Before Update
11. Lead After Update (OpportunityContactRoles now available)If “Enforce Validation and Triggers on Lead Conversion” is disabled, none of the Before triggers fire, but the After triggers still execute in the same order.
Key Considerations:
- The Lead Before Update trigger fires before the lead is actually converted (
isConverted = false). - The Lead After Update trigger fires after conversion (
isConverted = true). - Opportunity Contact Roles (
OpportunityContactRoles) are not yet available in the Opportunity After Insert trigger but become available in the Lead After Update trigger. - If merging into an existing Account or Contact, the Before and After triggers for those objects do not fire.
This order of execution is important for designing automation around lead conversion. Let me know if you need any further clarifications!
Kick Start Your Journey with Real-Time Project-Based Salesforce
Our Salesforce course is designed to provide a comprehensive understanding of the Salesforce platform, equipping you with the necessary skills to excel in the CRM industry. The program covers essential modules like Salesforce Admin, Developer, and AI, combining theoretical knowledge with hands-on practice. Through real-world projects and interactive exercises, you’ll gain the expertise to tackle business challenges using Salesforce solutions. Our experienced instructors ensure you develop both technical proficiency and industry-relevant insights to succeed in the Salesforce ecosystem.
In addition to technical training, our Salesforce training in Mumbai offers dedicated mentorship, certification support, and interview preparation to enhance your career prospects. You’ll have access to in-depth study resources, live project experience, and continuous guidance throughout your learning journey. By the end of the course, you’ll be fully prepared for certification exams and real-world applications, with problem-solving skills that employers value. Take the first step in your Salesforce career with us and explore exciting opportunities. Sign up for a Free Demo today!

Leave a Reply
You must be logged in to post a comment.