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
TanyrilTanyril 

Save error: Initial term of field expression must be a concrete SObject: LIST<Account>

I'm having some trouble with a class I'm creating. The purpose of this class is to essentially work around the Analytical Snapshot limit by batching the job- which is all fine but i'm getting the error in the title. Here's the code

 

global with sharing class AUMSnapshot implements Database.Batchable<sObject> {
   global final String Query;

   global AUMSnapshot() {
        this.Query = 'Select a.Id, a.navmfv2__Latest_AUM__c, a.navmfv2__AUM_as_of__c, a.Value__c, a.Research__c, a.Balanced__c, a.Government_MM__c, a.Hickory__c, a.NE_Tax_Free__c, a.Partners_Value__c, a.PIII__c, a.Short_Intermediate_Classes_combined__c  From Account a';
   }
   
   global AUMSnapshot(String query) {
        this.Query = query;
   }

   global Database.QueryLocator start(Database.BatchableContext BC) {
      return Database.getQueryLocator(Query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope) {
    
    List<Account> AccountAssets = (List<Account>) scope;
    
    List<Account> updateAccount = new List<Account>();
    
    for (Account AccountAsset : AccountAssets) {
	Historical_AUM__c haum = new Historical_AUM__c( Account__c = AccountAsset.Id, AUM__c = AccountAsset.navmfv2__Latest_AUM__c, Value__c = AccountAsset.Value__c, Research__c = AccountAsset.Research__c, Record_Date__c = AccountAsset.navmfv2__AUM_as_of__c, Balanced__c = AccountAsset.Balanced__c, Government_MM__c = ACcountAsset.Government_MM__c, NE_Tax_Free__c = AccountAsset.NE_Tax_Free__c, Hickory__c = AccountAsset.Hickory__c, Partners_Value__c = AccountAsset.Partners_Value__c, PIII__c = AccountAsset.PIII__c, Short_Intermediate__c = AccountAsset.Short_Intermediate_Classes_combined__c, UpsertID__c = AccountAssets.Id & AccountAsset.navmfv2__AUM_as_of__c);
	upsert haum UpsertID__c; 
	
    }
    
    update updateAccount;
    
   }

   global void finish(Database.BatchableContext BC){

   }
   
   public static testMethod void testBatch() {
    
    Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US', navmfv2__AUM_as_of__c = Date.today());
    insert a;
    
	Historical_AUM__c b = new Historical_AUM__c( Account__c = a.Id, AUM__c = a.navmfv2__Latest_AUM__c, Value__c = a.Value__c, Research__c = a.Research__c, Record_Date__c = a.navmfv2__AUM_as_of__c, Balanced__c = a.Balanced__c, Government_MM__c = a.Government_MM__c, NE_Tax_Free__c = a.NE_Tax_Free__c, Hickory__c = a.Hickory__c, Partners_Value__c = a.Partners_Value__c, PIII__c = a.PIII__c, Short_Intermediate__c = a.Short_Intermediate_Classes_combined__c, UpsertID__c = a.Id & a.navmfv2__AUM_as_of__c);
	upsert b;

    Test.StartTest();
    AUMSnapshot BatchClass = new AUMSnapshot();
    Database.executeBatch(BatchClass, 1);
    //BatchClass.execute(null, new List<sObject>{zipper});
    Test.StopTest();
   }
}

 

 

 The part where I declare haum is the offending line of code. I would appreciate any help.

Best Answer chosen by Admin (Salesforce Developers) 
TanyrilTanyril

I ended up just writing a very simple trigger to copy the info before an update.

All Answers

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

List<Account> AccountAssets = (List<Account>) scope;

 

Replace above line of code with the following piece of code...

 

List<Account> AccountAssets = new List<Account>();

for(Sobject s: scope){
    Account a = new Account();
    a = (Account)s;
    AccountAssets.add(a);
}

 

I dont see any usage of this statement..You can remove it.

update updateAccount;
sivaextsivaext

Hi 

 

The below code is wrong

List<Account> AccountAssets = (List<Account>) scope;
    
    List<Account> updateAccount = new List<Account>();
    
    for (Account AccountAsset : AccountAssets) {
	Historical_AUM__c haum = new Historical_AUM__c( Account__c = AccountAsset.Id, AUM__c = AccountAsset.navmfv2__Latest_AUM__c, Value__c = AccountAsset.Value__c, Research__c = AccountAsset.Research__c, Record_Date__c = AccountAsset.navmfv2__AUM_as_of__c, Balanced__c = AccountAsset.Balanced__c, Government_MM__c = ACcountAsset.Government_MM__c, NE_Tax_Free__c = AccountAsset.NE_Tax_Free__c, Hickory__c = AccountAsset.Hickory__c, Partners_Value__c = AccountAsset.Partners_Value__c, PIII__c = AccountAsset.PIII__c, Short_Intermediate__c = AccountAsset.Short_Intermediate_Classes_combined__c, UpsertID__c = AccountAssets.Id & AccountAsset.navmfv2__AUM_as_of__c);
	upsert haum UpsertID__c; 
	
    }
    

 

Change code below

 global void execute ( Database.BatchableContext BC, List<sObject> scope) {

    

for (sObject a:scope) {

 

Account acc= (account) a;

 you write whole query and inplace of upsert_ID_C = acc.id;

}

 

}

TanyrilTanyril

Sam_SFDC15- Thanks for the help, but I ended up getting the same error with your changes.

 

Sivaext- What do you mean in the line of your post below Account acc= (account) a;?

 

Maybe I'm going about this entirely the wrong way- I need to create a new Historical AUM record for each account on a monthly basis, pulling in the information from the account when the class is executed. I'm kind of new to apex programming but I thought the syntax for that would be basically the same I use when I'm writing a test class...

sivaextsivaext

Hi 

 

In batch class 

 

Three steps are there

 

1. start - querying  records on particular object

2. execute - we used list of querying and processed

        the syntax is

           global void execute (Database.BatchableContext BC , List<sObject> scope) {

               we can loop scope , scope is list of records.

        //Looping of querying records

          for(sObject a:scope) {

             // we need to define sobject  i.e we are querying records on account object.

              Account acc = (Account)a;

           

          }              

        }

3.finish 

TanyrilTanyril

I ended up just writing a very simple trigger to copy the info before an update.

This was selected as the best answer