You need to sign in to do that
Don't have an account?
Gabe Rothman
Can anyone tell me why this unit test is failing? Pulling my hair out trying to figure it out...
Trigger:
Service Class
Test:
Class.TestConvertLeadonActive.verifyleadConvert: line 13, column 1
14:47:09.467 (8467634625)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Lead: execution of AfterInsert
caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, An unexpected error occurred. Please include this ErrorId if you contact support: 1544795524-319229 (-1093901949): []
trigger Lead on Lead (after insert, after update) { if(trigger.isInsert || trigger.isUpdate){ ConvertLeadOnActiveService.convertLead(trigger.new); } if(trigger.isInsert){ List<lead> leads = new List<Lead>(); for(lead l : trigger.new){ if(l.PagerDuty_Account_ID__c != null) { leads.add(l); } } CreatePddOnLeadService.createPDD(leads); } if(trigger.isUpdate){ CreatePddOnLeadService.createPDD(CreatePddOnLeadService.filterPDIDIsNull(trigger.oldmap,trigger.new)); ReassociatePDDToAccountService.movePDD(ReassociatePDDToAccountService.filterConverted(trigger.oldmap,trigger.new)); } }
Service Class
public with sharing class ConvertLeadOnActiveService { public static void convertLead(list<lead> convertList) { for (Lead lead : convertList) { if (lead.isConverted == false && lead.State__c == 'Active'){ Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(lead.Id); String oppName = lead.Company; lc.setOpportunityName(oppName); LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1]; lc.setConvertedStatus(convertStatus.MasterLabel); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); } } } }
Test:
@isTest public class TestConvertLeadonActive { static testMethod void verifyleadConvert(){ Lead l = new Lead(); l.FirstName = 'Test'; l.LastName = 'Test'; l.Company = 'Test, Inc.'; l.Status = 'A. New-Open'; l.State__c = 'trial'; l.Email = 'test@test.com'; l.State__c = 'Active'; insert l; List<Lead> retrieveLead = [SELECT id FROM Lead WHERE id =: l.Id AND isConverted = true]; Integer size = retrieveLead.size(); system.assertEquals(1,size); } }Error Message:
Class.TestConvertLeadonActive.verifyleadConvert: line 13, column 1
14:47:09.467 (8467634625)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Lead: execution of AfterInsert
caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, An unexpected error occurred. Please include this ErrorId if you contact support: 1544795524-319229 (-1093901949): []
The best bet would be to start inserting some System.Debug statements throughout your code and comment out a bunch to see EXACTLY where it is failing. It could be the trigger stepping on itself (you appear to be doing many things to the same record at the same time) or just a violation of the order of execution somewhere.
Just start small and step it through.
thanks,
http://www.forcexplore.com/2014/07/wrapper-class-in-salesforce.html