+ Start a Discussion
Victor19Victor19 

Compilation error with batch apex test class

I get this error when I try to save my batch apex test class:

Error: Compile Error: Final member variables can only be assigned in their declaration statement or inside a constructor at line 88 column 16

 

Any suggestions or help would greatly help me out!

 

Below is my test class:

@isTest
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;    
            
        /* 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();
         testProd1.id = '01t60000002wbRd';
         testProd1.name = 'BC Advantage';
         testProd1.IsActive = True;
         insert testProd1;
         
        /* create 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,
        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' );
        EnImpts.add(EnImp);
      }
      insert EnImpts;
           

Test.StartTest();
 Enrollment_MainProcess enmp = new Enrollment_MainProcess();
88  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' +
                'LIMIT 200';
  ID batchprocessId = Database.executeBatch(enmp);
  Test.StopTest();

}

}

 

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Jeff MayJeff May

as the error in line 88 states, remove the final and you should be OK.

All Answers

Jeff MayJeff May

Looks like your batch class (not the test) has not set the query variable to public.

Victor19Victor19

The query variable in the batch class has been set to public.

 

I have no idea why I am still getting this error :(

Jeff MayJeff May

what is the line for the declaration?

Victor19Victor19

Its in line 88

 


 Enrollment_MainProcess enmp = new Enrollment_MainProcess();
88  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' +
                'LIMIT 200';
  ID batchprocessId = Database.executeBatch(enmp);
 

Jeff MayJeff May

I mean the declaration in your actual Batch class that line 88 is complaining about.

Victor19Victor19

Oh Sorry!

 

This is how we have declared in our batch class:

 

public final String Query;

 

We are still working on our batch class so it would be to early for me to put up the entire batch process code!

Jeff MayJeff May

as the error in line 88 states, remove the final and you should be OK.

This was selected as the best answer
Victor19Victor19

Thanks Jeff.. once I removed final it worked!