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

System.assert or any related methods to verify a record has been inserted into an object



I would like to use System.assert in my Batch Apex test class to verify if a record (passed some logic) has got inserted into an object.


Can anyone suggest an answer for my question.



Jeff MayJeff May

After the call to your batch class, add a SOQL select on the record and assert on the field values you get back.


Hi Jeff,


Am I doing it right below:

I am trying to assert on the Account Name field (highlighted in the code), if the name is equal to TestAccount4.


I am getting this Compile Error on assert statement: Initial term of field expression must be a concrete SObject

Could you please help me out.




public class Enrollment_MainProcess_TEST{

 static testMethod void testBatch(){

         /* create user */
         User salesUser =
           [SELECT Name, Lead_Rep_Number__c
            FROM User WHERE Lead_Rep_Number__c != null Limit 1];
        /* create account */  
         Account testacct1 = new Account();
         testacct1.Name = 'TestAccount4';
         testacct1.Type = 'Customer';
         insert testacct1;
         Account testacct2 = new Account();
         testacct2.Name = 'TestAccount44';
         testacct2.Type = 'Partner';
         insert testacct2;   
        /* create opportunity */
         Opportunity testOpp1 = new Opportunity();
         Date closedDate = date.newinstance(1950, 15, 1);
         Date EffectiveDate = date.newinstance(2050, 10, 9);            
         testOpp1.Name = 'Test Opportunity1';
         testopp1.AccountId = testacct1.Id;
         testOpp1.StageName ='Sold';
         testOpp1.CloseDate = closedDate;
         testOpp1.Effective_Date__c =  EffectiveDate;
         testOpp1.SBU__c = 'Small/Medium';
         testopp1.Market_Segment_New__c = '51-199';
         testopp1.Business_type__c = 'Renewal';
         testopp1.Division__c = '51-199 Renewals';   
         testopp1.Underwriting_Entity__c = 'MD';
         testopp1.Lead_Rep_Name_User__c = salesUser.Id;
         testOpp1.GeneralProducer__c = 'Direct';
         testOpp1.System__c = 'NASCO';    
         testOpp1.NASCO_Acct_ID__c = '12234';      
         insert testOpp1;
        /* create Product */
         Product2 testProd1 = new Product2(); = '01t60000002wbRd'; = 'BC Advantage';
         testProd1.IsActive = True;
         insert testProd1;
        /* create sample Enrollment Import */
         List <Enrollment_Import__c> EnImpts = new List<Enrollment_Import__c>();
         for(integer i = 0; i<200; i++){
         Enrollment_Import__c EnImp = new Enrollment_Import__c(
        Account_Name__c = 'TestAccount'+'i',
        Account_Number__c = '1223'+'i',             
        System__c = 'NASCO',
        Contracts__c = 50+i,
        Processed__c = FALSE,
        Risk__c = 'Non-Risk',
        Rpt_dt__c = '201301',
        Run_Dt__c = '02/09/2013 13:37:21',
        SFDC_Product__c = 'BC Advantage' );
      insert EnImpts;
 Enrollment_MainProcess enmp = new Enrollment_MainProcess();
  enmp.query = 'SELECT id, Rpt_Dt__c, Run_Dt__c, Account_Name__c, Account_Number__c, SFDC_Product__c, Contracts__c, System__c, Risk__c FROM Enrollment_Import__c WHERE Processed__c = FALSE';
  enmp.ProcessedType = 'M';
  ID batchprocessId = Database.executeBatch(enmp);
  System.assertEquals('TestAccount4', enmp.query.Account_Name__c);

Jeff MayJeff May

enmp.query is a string, you are trying to use it like an object.


Actually Jeff.. I fixed the issue.


Thanks for the response!