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
@login.ax974@login.ax974 

Error in map .. :(

Hi,

 

 Can someone please help me here - i am getting this error 

line 7, column 27: Method does not exist or incorrect signature: accountContractMap.get(String)

 

Map<Id, List<Contract>> accoutContractMap = new Map<Id, List<Contract>>();
//Prepare the map of Account Id as key and the list of contracts associated with it
for(Contract c: [SELECT Id, AccountId, CreatedDate, Status from Contract Limit 100])
{
if(accoutContractMap.get(c.AccountId) != null)
{
System.debug(accountContractMap.get(c.Status));
accountContractMap.get(c.AccountId).add(c);
}
else
{
List<Contract> temp = new List<Contract>();
temp.add(c);
accountContractMap.put(c.AccountId, temp);
}
}
System.debug('Map of account id and the list of contracts is' + accoutContractMap);

 

thanks so much.

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

accoutContractMap

accountContractMap

 

Looks like you have a misspelling. Apex can't find a variable when you spell it differently.

All Answers

abhishektandon2abhishektandon2

Hi

Problem in these 2 lines

 

1) System.debug(accountContractMap.get(c.Status));

 

According to your code y should only callaccoutContractMap.get(c.AccountId) 


2) ccountContractMap.get(c.AccountId).add(c);

.add(c) is invalid

 

you should create a seperate List and add items to that

@login.ax974@login.ax974

Hi,

Thanks so much for the reply. But even after changing it gives me the same error. See the changed code below. Really not able to understand whats wrong here.

line 8, column 15: Method does not exist or incorrect signature: accountContractMap.get(Id)

 

Map<Id, List<Contract>> accoutContractMap = new Map<Id, List<Contract>>();
//Prepare the map of Account Id as key and the list of contracts associated with it
for(Contract c: [SELECT Id, AccountId, CreatedDate, Status from Contract Limit 100])
{
Id key = c.AccountId;
if(accoutContractMap.get(key) != null)
{
System.debug(accountContractMap.get(key));
List<Contract> temp = accountContractMap.get(key);
temp.add(c);
accoutContractMap.put(key, temp);
}
else
{
List<Contract> temp = new List<Contract>();
temp.add(c);
accountContractMap.put(key, temp);
}
}
System.debug('Map of account id and the list of contracts is' + accoutContractMap);

abhishektandon2abhishektandon2

Try This

Map<Id, List<Contract>> accoutContractMap = new Map<Id, List<Contract>>();

for(Contract c: [SELECT Id, AccountId, CreatedDate, Status from Contract Limit 100])
{
Id key = c.AccountId;
if(accoutContractMap.containsKey(key))
{
System.debug(accoutContractMap.get(key));
List<Contract> TempList=accoutContractMap.get(key);
TempList.add(c);
accoutContractMap.put(key,TempList);
}
else
{
List<Contract> TempList=accoutContractMap.get(key);
TempList.add(c);
accoutContractMap.put(key,TempList);
}
}
System.debug('Map of account id and the list of contracts is' + accoutContractMap);

craigmhcraigmh

accoutContractMap

accountContractMap

 

Looks like you have a misspelling. Apex can't find a variable when you spell it differently.

This was selected as the best answer
@login.ax974@login.ax974

Thanks so much ... it worked ..  my bad ... probably too tired and needed a fresh set of eyes ... thanks again ... :(

craigmhcraigmh

I say that programmers are simply machines that convert caffeine to code. Sounds like you're low on raw input, hehe.