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
Jerry ClifftJerry Clifft 

Hoping somone can help me with a test class on this lead clone trigger

I have a working trigger, if criteria is met, 2 leads are cloned and assigned to 2 additional partners. But I can not seem to figure out a test class for it.

 

trigger FTGClone on Lead (after insert)
{
Lead L = trigger.new[0];
if(L.Category__c  == 'FTG' && L.Clone_Version__c == '0' && L.LeadSource != 'Self Generated' && L.Number_of_Units__c >= 50)
{
Lead[] LeadClone = new Lead[0];

map<id,Lead> entries = new map<id,Lead>(); 

for(Lead record:trigger.new)
entries.put(record.id,null); 
entries.putall([select id,Name, Company, LastName, FirstName,Lead_Source_External__c, Number_of_TVs__c, Email, Location_of_Service__c, Building_Stories__c, MobilePhone, Phone, Business_Phone_Ext__c, Business_Phone__c, Number_of_Units__c, Number_of_Locations__c, Type_of_Business__c, Business_Address__c, Business_State__c, Business_City__c, Business_Zipcode__c from Lead where id in :entries.keyset()]); 


for(Lead record:trigger.new) 
LeadClone.add(new Lead ( Ownerid='00G60000001G9uA', Original_Lead_Id__c=record.Id,Company=entries.get(record.id).Company,LastName=entries.get(record.id).LastName,FirstName=entries.get(record.id).FirstName,Clone_Version__c='1',Lead_Source_External__c=entries.get(record.id).Lead_Source_External__c,Number_of_TVs__c=entries.get(record.id).Number_of_TVs__c, Email=entries.get(record.id).Email, Location_of_Service__c=entries.get(record.id).Location_of_Service__c, Building_Stories__c=entries.get(record.id).Building_Stories__c, MobilePhone=entries.get(record.id).MobilePhone, Phone=entries.get(record.id).Phone, Business_Phone_Ext__c=entries.get(record.id).Business_Phone_Ext__c, Business_Phone__c=entries.get(record.id).Business_Phone__c, Number_of_Units__c=entries.get(record.id).Number_of_Units__c, Number_of_Locations__c=entries.get(record.id).Number_of_Locations__c, Type_of_Business__c=entries.get(record.id).Type_of_Business__c, Business_Address__c=entries.get(record.id).Business_Address__c, Business_State__c=entries.get(record.id).Business_State__c, Business_City__c=entries.get(record.id).Business_City__c, Business_Zipcode__c=entries.get(record.id).Business_Zipcode__c));

for(Lead record:trigger.new) 
LeadClone.add(new Lead ( Ownerid='00G60000001G9uF', Original_Lead_Id__c=record.Id,Company=entries.get(record.id).Company,LastName=entries.get(record.id).LastName,FirstName=entries.get(record.id).FirstName,Clone_Version__c='2',Lead_Source_External__c=entries.get(record.id).Lead_Source_External__c,Number_of_TVs__c=entries.get(record.id).Number_of_TVs__c, Email=entries.get(record.id).Email, Location_of_Service__c=entries.get(record.id).Location_of_Service__c, Building_Stories__c=entries.get(record.id).Building_Stories__c, MobilePhone=entries.get(record.id).MobilePhone, Phone=entries.get(record.id).Phone, Business_Phone_Ext__c=entries.get(record.id).Business_Phone_Ext__c, Business_Phone__c=entries.get(record.id).Business_Phone__c, Number_of_Units__c=entries.get(record.id).Number_of_Units__c, Number_of_Locations__c=entries.get(record.id).Number_of_Locations__c, Type_of_Business__c=entries.get(record.id).Type_of_Business__c, Business_Address__c=entries.get(record.id).Business_Address__c, Business_State__c=entries.get(record.id).Business_State__c, Business_City__c=entries.get(record.id).Business_City__c, Business_Zipcode__c=entries.get(record.id).Business_Zipcode__c));


insert LeadClone; }}
arjunmarjunm

hi jerry

 

try like this

 

@istest
public  class classname{

 

static testmethod void methodname()

{

        //add ur fields and insert  first partners
          Lead l = new lead();
          l.OwnerId = '00G60000001G9uA' ;
          l.FirstName = 'test';
          l.LastName= 'b';
          l.Company = 'Company';
          l.Status = 'Open - Not Contacted';
          insert l; 

 

        //add ur fields and insert  2 partners

           Lead la = new lead();
          la.OwnerId = '00G60000001G9uF' ;
          la.FirstName = 's';
          la.LastName= 'Name';
          la.Company = 'Companyd';
          la.Status = 'Open - Not Contacted';
          insert la;

 

    }

   }

 

 

 

thanks & regards

arjun