You need to sign in to do that
Don't have an account?
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.
accoutContractMap
accountContractMap
Looks like you have a misspelling. Apex can't find a variable when you spell it differently.
All Answers
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
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);
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);
accoutContractMap
accountContractMap
Looks like you have a misspelling. Apex can't find a variable when you spell it differently.
Thanks so much ... it worked .. my bad ... probably too tired and needed a fresh set of eyes ... thanks again ... :(
I say that programmers are simply machines that convert caffeine to code. Sounds like you're low on raw input, hehe.