Contents
How to create test class for lead conversion trigger?
I have a trigger that takes the Converted Contact and updates a custom contact lookup field on the Converted Opportunity with that Contact. This trigger is working fine, but I am having trouble creating the test class.
Why is my lead conversion test erroring out?
If that’s also the case with your sales process, then you need to add those critera to your trigger. The reason your trigger is erroring out is that in your test class, you are calling update testLead; which will convert your testLead, and then you are converting it once again later in your test class.
How to change lead status before or after conversion?
The problem is that the lead is set to “Read only” once the conversion is done. The conversion process itself changes the Lead Status — and by default triggers aren’t fired. So a before trigger on the Lead being converted won’t work because of the order the Trigger is fired before the lead is converted.
How to trigger on lead conversion in Salesforce?
Hm, my undestanding is that the Lead becomes Read Only after the updated record is saved to the database, thus I thought a before update Trigger would be the only way to update the picklist before that happens. Wouldn’t any Process Builder update fire after it becomes Read Only and consequently error out?
What is the dmlexception for converting a lead?
System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [] Your trigger is set up so that *any* lead that is updated is converted. Typically, lead converts only happen if certain criteria are met.
Do you need to test a trigger on a contact object?
As a result of this trigger on McLabs2__Ownership__c (if exist) will be invoked, but you have to test a trigger on Contact object. Thus you need to insert an account and after that update it because your contact trigger works in after update mode. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.
Is there a test class for trigger in Salesforce?
I just wrote this trigger and it seems to be working fine in dev, I need to move it into production, however, the test class I wrote passes the test but does not cover the trigger. Any help would be greatly appreciated. I am a bit green here.