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
sapana.personal1.389616626807929E12sapana.personal1.389616626807929E12 

System.AssertException

Hi,

I have written a test method in my test class to test the after update event on Lead trigger. On update of the Lead record child Staff_Information__c record should be updated. The trigger is working fine. But my test method fails giving the following error 'Assertion Failed: Expected: Test FN, Actual: Update - Test First Name AS1'. But actually I am providing here the correct values. Could anyone point out what the mistake is? Here is my code.

@isTest(SeeAllData = true)
public static void Test_ENT_AdvisoryService_Triggers4()
  {
    // Initialise variables. 
    List<Lead> lstLeads = new List<Lead>();
    List<ENT_AS_Staff_Information__c> lstASStaffInformation = new List<ENT_AS_Staff_Information__c>();
    List<Lead> lstASLeadsToUpdate = new List<Lead>();
   
    Test.startTest();
   
    // Insert test Lead records.
    lstLeads = GenerateAdvisoryServicesTestLeads(100);
    System.assertEquals(lstLeads.size(),100);
   
    if(lstLeads != null && lstLeads.size() > 0)
    {
      lstASStaffInformation = GenerateTestASStaffInformationForLeads(lstLeads);
    }
       
    System.assertEquals(lstASStaffInformation.size(),100);
    System.assertEquals(lstASStaffInformation[0].Member_First_Name__c, 'Test FN');
     
    if(lstLeads != null && lstLeads.size() > 0)
    {
        for(Lead leadToUpdate: lstLeads)
        {    
            leadToUpdate.Additional_info_on_services__c = 'Update - Test Additional information on service';
            leadToUpdate.Expertise_of_key_personal__c = 'Update - Test Key Personal skills';
            leadToUpdate.Is_your_organization_registered_with_SAM__c  = 'No';
            leadToUpdate.Languages_conversationally__c = 'Update - English, Update - French';
            leadToUpdate.Languages_High_proficiency__c = 'Update - English';
            leadToUpdate.FirstName = 'Update - Test First Name AS1';
            leadToUpdate.LastName = 'Update - Test Last Name AS1';
            leadToUpdate.Job_Title__c = 'Update - Asset Manager';
            leadToUpdate.Experience_with_cities__c = 'Update - Columbia, Update - New York';
            leadToUpdate.Experience_with_coordination__c = 'Update - Test Description';
            leadToUpdate.Place_availability__c = 'Update - Columbia';
            leadToUpdate.Rate_support__c = 'Update - 60 USD for 1 day';
            leadToUpdate.References_name__c = 'Update - Test Reference';
            leadToUpdate.SAM_Expiration_Date__c = Date.today();              
            leadToUpdate.Company = 'Update - Test Company';
            leadToUpdate.Title = 'Test Title';
            leadToUpdate.Email = 'test@gmail.com';
            leadToUpdate.References_organization__c = 'Test Ref Org';
            leadToUpdate.References_email__c = 'testref@gmail.com';
            leadToUpdate.References_phone__c = '(401)-402-4433';
            leadToUpdate.References_title__c = 'Test Ref Title';
            leadToUpdate.Website = 'testweb.com';
            leadToUpdate.Contact_phone_number__c = '(456)-456-4567';
            leadToUpdate.Contact_Fax_Number__c = '(477)-477-7744';
            leadToUpdate.DUNS_Number__c = '12345';
            leadToUpdate.Federal_EIN__c  = '12345';
            leadToUpdate.Street = 'Test Street';
            leadToUpdate.City = 'Test City';
            leadToUpdate.State = 'NY';
            leadToUpdate.PostalCode = '54321-4321';
            leadToUpdate.Country = 'US';           
            lstASLeadsToUpdate.add(leadToUpdate); 
         } 
    } 
       
    // Check that list of updated Lead records is not empty and if not update the list.
    if(lstASLeadsToUpdate.size() > 0)
    {
        UPDATE lstASLeadsToUpdate;
    }
    System.assertEquals(lstASLeadsToUpdate.size(),100);
       
    // Update the related Staff Information record.
    if(lstASStaffInformation.size() > 0)
    {
        UPDATE lstASStaffInformation;
    }
    System.assertEquals(lstASStaffInformation.size(),100);
    // Check whether Staff Information records for Advisary Service Leads are updated.
    if(lstASStaffInformation.size()>0)
    {
        System.assertEquals(lstASStaffInformation[0].Member_first_name__c, 'Update - Test First Name AS1');
        System.assertEquals(lstASStaffInformation[0].Member_last_name__c, 'Update - Test Last Name AS1');
        System.assertEquals(lstASStaffInformation[0].Member_Title__c , 'Test Title');
        System.assertEquals(lstASStaffInformation[0].Rate_support__c, 'Update - 60 USD for 1 day');
        System.assertEquals(lstASStaffInformation[0].Selec_if_the_organization_is_registered__c,'No');
        System.assertEquals(lstASStaffInformation[0].Place_availability__c ,'Update - Columbia');
        System.assertEquals(lstASStaffInformation[0].Additional_info_on_services__c, 'Update - Test Additional information on service');
        System.assertEquals(lstASStaffInformation[0].Languages_high_profeciency__c,'Update - English' );
        System.assertEquals(lstASStaffInformation[0].Languages_conversationally__c,'Update - English, Update - French');
        System.assertEquals(lstASStaffInformation[0].Email__c,'test@gmail.com');
        System.assertEquals(lstASStaffInformation[0].Expertise_of_key_personnel__c,'Update - Test Key Personal skills');
        System.assertEquals(lstASStaffInformation[0].Narrative_Expertise_of_key_personal__c , 'Update - Test Key Personal skills');
        System.assertEquals(lstASStaffInformation[0].Narrative_Experience_with_cities__c, 'Update - Columbia, Update - New York');
        System.assertEquals(lstASStaffInformation[0].Narrative_Experience_with_coordination__c,'Update - Test Description');
        System.assertEquals(lstASStaffInformation[0].Reference_organization__c, 'Test Ref Org');
        System.assertEquals(lstASStaffInformation[0].Reference_email__c, 'testref@gmail.com');
        System.assertEquals(lstASStaffInformation[0].Reference_name__c,'Update - Test Reference');
        System.assertEquals(lstASStaffInformation[0].Reference_phone__c,'(401)-402-4433' );
        System.assertEquals(lstASStaffInformation[0].Reference_title__c,'Test Ref Title' );
        System.assertEquals(lstASStaffInformation[0].SAM_Expiration_Date__c,Date.today()) ;
        System.assertEquals(lstASStaffInformation[0].Website__c, 'testweb.com');
        System.assertEquals(lstASStaffInformation[0].Contact_phone_number__c,'(456)-456-4567');
        System.assertEquals(lstASStaffInformation[0].Contact_Fax_Number__c, '(477)-477-7744');
        System.assertEquals(lstASStaffInformation[0].DUNS_Number__c,'12345');
        System.assertEquals(lstASStaffInformation[0].Federal_EIN__c, '12345');
        System.assertEquals(lstASStaffInformation[0].Address__c ,String.valueOf('Test Street'+'Test City'+'NY'+'54321-4321'+'US'));
    }
        Test.stopTest();
  }
pradeep naredlapradeep naredla
Hi sapana,

The error in ur code is at this line ---------------System.assertEquals(lstASStaffInformation[0].Member_First_Name__c, 'Test FN');-----------

The system.assert method will check the condition and if it is not satisfied it will through the error so i think there is no record in ur database with a name    (test FN).

Check it and post again if u have further problems..

Thanks,
pradeep.
sapana.personal1.389616626807929E12sapana.personal1.389616626807929E12
Hi Pradeep,

Thanks for your reply

I get this error: 'Assertion Failed: Expected: Test FN, Actual: Update - Test First Name AS1'. That means my Staff_Information__c record is not updated and it still has the previous value which is 'Test FN'. It should actually have the value 'Test First Name AS1' after being updated. So I guess the records are not getting updated and am not getting why.  If you could help me out to find the reason.
pradeep naredlapradeep naredla
Hi,
  Can u post ur trigger once 

Thanks.
sapana.personal1.389616626807929E12sapana.personal1.389616626807929E12
Hi,

I have wriiten an apex method which holds the trigger logic and am calling this method from Lead trigger.


// Below function will be called from Lead Trigger
       public static Void AdvisoryServiceLeadAfterInsertUpdate(List<Lead> newLeads, Map<ID, Lead> oldLeads)
       {     
            List<RecordTypeMap__c> advLeadRecordTypes = [SELECT RecordTypeId__c, Record_Type_Name__c, sObject__c FROM RecordTypeMap__c where sObject__c = 'Lead' and Record_Type_Name__C = :ENT_AS_ConstantHelper.ASLeadRecordType  and Is_Active__c = true LIMIT 1];
           
            if(advLeadRecordTypes.size() > 0)
            {
                ID asLeadRecordType = advLeadRecordTypes[0].RecordTypeId__c;
               
                // Initialize the list, Set and maps for Contact, Account, Staff Information, Staff Rate, etc.
                List<Contact> lstContactsForUpdate = new List<Contact>();
                List<Account> lstAccountsForUpdate = new List<Account>();      
                List<ENT_AS_Staff_Information__c> lstStaffInformationToUpdate = new List<ENT_AS_Staff_Information__c>();         
                List<ENT_AS_Staff_Rate__c> lstStaffRateToUpdate = new List<ENT_AS_Staff_Rate__c>();          
                List<Lead> lstConvertedLeads = new List<Lead>();
                List<Lead> lstNonConvertedLeads = new List<Lead>();
                SET<ID> setOfConvertedLeads = new SET<ID>();     
                SET<ID> setOfNonConvertedChangedLeads = new SET<ID>();      
              
       
                // Iterate through leads passed into trigger
                if(newLeads != null && newLeads.size() > 0)
                {
                    for(Lead newLead : newLeads)
                    {
                        // Go inside only if the current iterating lead is an Advisory Services Lead
                        if(newLead.RecordTypeId == asLeadRecordType)
                        {
                            // Check if trigger is converted then only, execute internal code
                            if(trigger.isAfter && trigger.isUpdate)
                            {                                
                                        setOfNonConvertedChangedLeads.add(newLead.ID);
                                        lstNonConvertedLeads.add(newLead);                                 
                            }            
                        }
                    }
                } 
              // Call method to be executed for non converted leads on lead update.
            OnNonConvertedLeadUpdateOtherObjects(setOfNonConvertedChangedLeads,lstNonConvertedLeads);
          }
       }

/***********************************************************************************************/


// Following function would be called from Lead trigger when the Lead is updated to update the related info in Staff Information record.
       private static void OnNonConvertedLeadUpdateOtherObjects(Set<ID> setOfNonConvertedChangedLeads, List<Lead> lstNonConvertedLeads)
       {
           
            List<ENT_AS_Staff_Information__c> lstStaffInformationToUpdate = new List<ENT_AS_Staff_Information__c>();
            Map<ID, ENT_AS_Staff_Information__c> mapLeadAndStaffInformation = new Map<ID, ENT_AS_Staff_Information__c>();
           
            if(setOfNonConvertedChangedLeads.size()>0)
            {
               
               for(ENT_AS_Staff_Information__c staffInfo :[
                                                              SELECT ID, Name, Lead__c, Member_first_name__c, Member_last_name__c, Member_Title__c, Rate_support__c, Selec_if_the_organization_is_registered__c, Place_availability__c,
                                                              Additional_info_on_services__c, Languages_high_profeciency__c, Languages_conversationally__c, Email__c, Expertise_of_key_personnel__c, Contact_Fax_Number__c,
                                                              Narrative_Expertise_of_key_personal__c, Narrative_Experience_with_cities__c, Narrative_Experience_with_coordination__c, Website__c, Contact_phone_number__c,
                                                              Federal_EIN__c, Address__c, Reference_organization__c, Reference_email__c, Reference_phone__c, Reference_title__c, SAM_Expiration_Date__c, DUNS_Number__c
                                                              FROM ENT_AS_Staff_Information__c
                                                              WHERE Lead__c =: setOfNonConvertedChangedLeads      
                                                          ])
               {
                     mapLeadAndStaffInformation.put(staffInfo.Lead__c, staffInfo);
               }
              
               for(Lead affectedLead:lstNonConvertedLeads)
               {
                    if(mapLeadAndStaffInformation.containsKey(affectedLead.ID))
                    {
                          ENT_AS_Staff_Information__c StaffInformationToUpdate =  mapLeadAndStaffInformation.get(affectedLead.ID);
                          StaffInformationToUpdate.Member_first_name__c = affectedLead.FirstName;
                          StaffInformationToUpdate.Member_last_name__c = affectedLead.LastName;
                          StaffInformationToUpdate.Member_Title__c = affectedLead.Title;
                          StaffInformationToUpdate.Rate_support__c = affectedLead.Rate_support__c;
                          StaffInformationToUpdate.Selec_if_the_organization_is_registered__c  = affectedLead.Is_your_organization_registered_with_SAM__c;
                          StaffInformationToUpdate.Place_availability__c = affectedLead.Place_availability__c;
                          StaffInformationToUpdate.Additional_info_on_services__c = affectedLead.Additional_info_on_services__c;
                          StaffInformationToUpdate.Languages_high_profeciency__c= affectedLead.Languages_High_proficiency__c;
                          StaffInformationToUpdate.Languages_conversationally__c = affectedLead.Languages_conversationally__c;
                          StaffInformationToUpdate.Email__c= affectedLead.Email;
                          StaffInformationToUpdate.Expertise_of_key_personnel__c = affectedLead.Expertise_of_key_personnel__c;
                          StaffInformationToUpdate.Narrative_Expertise_of_key_personal__c = affectedLead.Expertise_of_key_personal__c;
                          StaffInformationToUpdate.Narrative_Experience_with_cities__c= affectedLead.Experience_with_cities__c;
                          StaffInformationToUpdate.Narrative_Experience_with_coordination__c = affectedLead.Experience_with_coordination__c;
                          StaffInformationToUpdate.Reference_organization__c = affectedLead.References_organization__c;
                          StaffInformationToUpdate.Reference_email__c = affectedLead.References_email__c;
                          StaffInformationToUpdate.Reference_name__c = affectedLead.References_name__c;
                          StaffInformationToUpdate.Reference_phone__c = affectedLead.References_phone__c;
                          StaffInformationToUpdate.Reference_title__c = affectedLead.References_title__c;
                          StaffInformationToUpdate.SAM_Expiration_Date__c = affectedLead.SAM_Expiration_Date__c ;
                          StaffInformationToUpdate.Website__c = affectedLead.Website ;
                          StaffInformationToUpdate.Contact_phone_number__c = affectedLead.Contact_phone_number__c ;
                          StaffInformationToUpdate.Contact_Fax_Number__c = affectedLead.Contact_Fax_Number__c;
                          StaffInformationToUpdate.DUNS_Number__c = affectedLead.DUNS_Number__c;
                          StaffInformationToUpdate.Federal_EIN__c = affectedLead.Federal_EIN__c;
                          StaffInformationToUpdate.Address__c = String.ValueOf(affectedLead.Street+' '+affectedLead.City+' '+affectedLead.State+' '+affectedLead.PostalCode+' '+affectedLead.Country);
                          lstStaffInformationToUpdate.add(StaffInformationToUpdate);
                    }
               }
              
               // Check that list of updated Staff Information records is not empty.
               if(lstStaffInformationToUpdate.size()>0)
               {
                   UPDATE lstStaffInformationToUpdate;
               }
               
               
             
            }  
        }