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
Erik John PErik John P 

APEX test class for trigger

Hello Community,

I do apologize as this is my second contact in less than a week, but we are very close to importing an apex class from sandbox to production, and I am running into a roadblock with some code in production that I did not write.  it needs a test class in order for me to import my apex class.    would anyone be able to provide assistance with writing a test class for a trigger?  trigger is below:

trigger ELQA_LeadConvert_Update_Marketing_Trigger on Lead (after update) 
{

    Set<Id> convertedids = new Set<Id>();
    map<string,string> emailsToChangeInEloqua = new map<string,string>();
    map <Id,Id> leadsAndContacts = new map <Id,Id>();
         for (Lead objLead : Trigger.new)
        {
           lead oldLead = Trigger.oldMap.get(objLead.Id);
           if(oldLead.IsConverted == false && objLead.IsConverted == true)
           {
               convertedids.add(objLead.Id);
               leadsAndContacts.put(objLead.Id,objLead.ConvertedContactId);
           }
           
           if(String.isNotBlank(objLead.email) && String.isNotBlank(oldLead.email) && objLead.email != oldLead .email){
                emailsToChangeInEloqua.put(oldLead.email, objLead.email);
            }
        }
        
         
        
         if(!convertedids.isEmpty()) 
         {
             ELOQUA__Marketing_Activity__c[] objMarketing = [SELECT id, ELOQUA__Lead__c, ELOQUA__Contact__c 
                                                             FROM ELOQUA__Marketing_Activity__c 
                                                             WHERE ELOQUA__Lead__c IN :convertedids];
             if(!objMarketing.isEmpty()) 
             {
                 for(ELOQUA__Marketing_Activity__c obj: objMarketing)
                  {
                      obj.ELOQUA__Contact__c = leadsAndContacts.get(obj.ELOQUA__Lead__c );
                  }
                  
                  update objMarketing;
             }
                                                      
         }
         
         if( emailsToChangeInEloqua.size() > 0 ) {
              ChangeEloquaEmailAddressCls.ChangeEloquaEmailAddress(emailsToChangeInEloqua);
        }
        
        LeadTriggerHandler.afterInsert(Trigger.new,Trigger.oldMap);