I am creating a batch process that looks at all records for the custom object enrollment__c
that have a null account_team__c
field. That field is a lookup to the account_team__c
custom object. The naming convention of that account_team__c
object is the year and the account name. So something like 2022 Acme Inc
The map that I created contains a string and a custom object. I declare the map with the following:
Map<String, List<Account_Team__c>> accountAtsMap2 =new Map<String, List<Account_Team__c>> ();
Everything gets populated in the map as expected but when I to add code to update the missing value, I get an error, Variable does not exist: id
Here is a record from the map (via debug)
14:36:29:027 USER_DEBUG [139]|INFO| 4 here is the ATName (Account_Team__c:{Id=a02S000000H0up9IAB, Name=2022 Test Prospect 1, Account_del__c=001S000001KbEBWIA3, Year__c=2022})
This is the line that won't save in VS because of the variable does not exist: id error:
system.debug(logginglevel.info, ' 4 here is the ATName ' + accountAtsMap2.get(atName).id);
Am I getting this error because I'm using a string instead of an ID in my map? Here is the full code:
global void execute(Database.BatchableContext ctx, List<Sobject> scope){
// Cycle through the first time to build a list of related account Id's from the ES's queried
//also add the enrollment summary to a list to be used later in code
List<Id> accountIds = new List<Id>();
for (sObject s : scope) {
Health_Enrollment_Summary__c es = (Health_Enrollment_Summary__c)s;
accountIds.add(es.account__c);
}
// Retrieve a list of all account teams using account id from ES's queried
List<Account_Team__c> atList = [
Select Id, Name, Account_del__c, Year__c, Account_del__r.name
from Account_Team__c
where Account_del__c in : accountIds];
//create a map to hold the account id and related account team records
Map<String, List<Account_Team__c>> accountAtsMap2 =new Map<String, List<Account_Team__c>> ();
//populate the map with Account Team Name / Account Team
for (Account_Team__c at : atList) {
//create name of account team to use for lookup into map
string tempAtname = at.year__c + ' ' + at.Account_del__r.Name ;
string AtName;
//trim name to a max of 80 charachters
if (tempAtName.length()>80){
AtName = tempAtName.substring(0,80);
}
else{
AtName = tempAtName;
}
List<Account_Team__c> tempList2 = new List<Account_Team__c>();
if (accountAtsMap2.containsKey(ATName)) {
tempList2 = accountAtsMap2.get(AtName);
}
tempList2.add(at);
accountAtsMap2.put(Atname, tempList2);
} //end for loop for scope
//test looping accountAtsMap2
for (sObject s : scope) {
Health_Enrollment_Summary__c es = (Health_Enrollment_Summary__c)s;
string tempAtname = es.year__c + ' ' + es.Account__r.Name ;
string AtName;
//trim name to a max of 80 charachters
if (tempAtName.length()>80){
AtName = tempAtName.substring(0,80);
}
else{
AtName = tempAtName;
}
//if es record has the account team field null, update
if(es.account_team__c == null){
system.debug(logginglevel.info, ' 3 here is the ATName ' + AtName);
if (accountAtsMap2.containsKey(AtName)) {
system.debug(logginglevel.info, ' 4 here is the ATName ' + accountAtsMap2.get(atName).Year_);
// es.account_team__c = accountAtsMap2.get(atName).Id;
//fill in the account team fields on ES
// system.debug(logginglevel.info, '2 here is the es with missing AT' + es.Name);
}
}
} //end of for loop on scope
} //end of execute method