You need to sign in to do that
Don't have an account?
muriel
Subquery and Map
HI,
I have trying to put the subquery into a second map as so:
Map<id,Case> caseToUpdate = new Map<id,Case>([select id, status,recordtypeid,Response_Time_Remaining__c,(select id , timeremaininginmins from CaseMilestones where MilestoneType.Name like '%response%') from case where status='new' and recordtypeid='012200000005ZLF']);
Map<id,CaseMilestone> CaseMilestoneMap = new Map<id,CaseMilestone>();
for(Case tempCase:caseToUpdate){
for(CaseMilestone cm:caseToUpdate.CaseMilestones){
CaseMilestoneMap.put(cm.id,cm);
}
}
i am getting "Compile Error: Initial term of field expression must be a concrete SObject: Map<Id,Case>" . It is pointing to " for(CaseMilestone cm:caseToUpdate.CaseMilestones){" .
i am pretty sure we can retrieve the subqeury and put it in a diff map...
what am i doing wrong?
I have trying to put the subquery into a second map as so:
Map<id,Case> caseToUpdate = new Map<id,Case>([select id, status,recordtypeid,Response_Time_Remaining__c,(select id , timeremaininginmins from CaseMilestones where MilestoneType.Name like '%response%') from case where status='new' and recordtypeid='012200000005ZLF']);
Map<id,CaseMilestone> CaseMilestoneMap = new Map<id,CaseMilestone>();
for(Case tempCase:caseToUpdate){
for(CaseMilestone cm:caseToUpdate.CaseMilestones){
CaseMilestoneMap.put(cm.id,cm);
}
}
i am getting "Compile Error: Initial term of field expression must be a concrete SObject: Map<Id,Case>" . It is pointing to " for(CaseMilestone cm:caseToUpdate.CaseMilestones){" .
i am pretty sure we can retrieve the subqeury and put it in a diff map...
what am i doing wrong?
if you want to loop through values(cases) in the Map<Id,Case> caseToUpdate then below for loop will work.
for(Case tempCase:caseToUpdate.values()){
... your logic
}
if you want to loop through keys(Ids) in the Map<Id,Case> caseToUpdate then below for loop will work.
for(Id i:caseToUpdate.keyset()){
... your logic
}
You won't be able to loop through map as it is.
Could you please let me know if you need any more help.
Regards,
BDatla
Regards,
BDatla
All Answers
Please use the below code :
for(Case tempCase:caseToUpdate.values()){
for(CaseMilestone cm:tempCase.CaseMilestones){
CaseMilestoneMap.put(cm.id,cm);
}
}
Regards,
BDatla
Can you please let me know the issue resolved or not ?
Regards,
BDatla
looking better
but it is now showing:
Loop must iterate over a collection type Map<Id,Case>
pointing at
for(Case tempCase:caseToUpdate){
might have to review the logic here and see if i can do it differently
if you want to loop through values(cases) in the Map<Id,Case> caseToUpdate then below for loop will work.
for(Case tempCase:caseToUpdate.values()){
... your logic
}
if you want to loop through keys(Ids) in the Map<Id,Case> caseToUpdate then below for loop will work.
for(Id i:caseToUpdate.keyset()){
... your logic
}
You won't be able to loop through map as it is.
Could you please let me know if you need any more help.
Regards,
BDatla
Regards,
BDatla
makes sense