We have a unique business request to have a lead duplicated when it is converted in order for a secondary sales rep try selling to the lead. below is the code that grabs the lead when it falls into a specific category, and re-creates the lead and assigns it to a secondary user ID already specified on the Lead record.
How can I test that this second record is create when there is no relation to the first one?
private void leadDupConvert()
{
List<Lead> LeadsToDup = new list<Lead>();
List<Lead> duplicatedLead = new list <Lead>();
for( Lead myLead : (List<Lead>)Trigger.new)
{
Lead oldLeadDetails = ((Map<Id, Lead>)Trigger.oldMap).get(myLead.ID);
if(myLead.Dual_Intent__c == TRUE && myLead.IsConverted && myLead.Lead_Secondary_Owner_ID__c != NULL && !oldLeadDetails.isConverted && firstRun)
{
LeadsToDup.add(myLead);
}
}
if(LeadsToDup.size() > 0)
{
for(Lead lea: LeadsToDup)
{
Lead l = new Lead();
l.FirstName = lea.FirstName;
l.LastName = lea.LastName;
l.Company = lea.Company;
l.Email = lea.Email;
l.Phone = lea.Phone;
l.Dual_Intent__c = FALSE;
l.OwnerId = lea.Lead_Secondary_Owner_ID__c;
l.Lead_Assigned__c = TRUE;
l.Status = 'Open';
l.RecordTypeId = lea.RecordTypeId;
duplicatedLead.add(l);
}
if(duplicatedLead.size()>0)
{
insert duplicatedLead;
}
}
}
So far the test code portion I have is as follows:
Database.LeadConvert le = new database.LeadConvert();
le.setLeadId(lea.id);
le.setDoNotCreateOpportunity(false);
le.setConvertedStatus('Existing Opportunity');
Database.LeadConvertResult lcr = Database.convertLead(le);
System.assert(lcr.isSuccess());
Can't figure out anything after this...