You need to sign in to do that
Don't have an account?
Luca Benedettini 7
Apex Error help me please
Hi guys.I need in an apex class a Map of Cases ID with their Attachemnts and a List with that Attachment. Now i write this:
Map<Id, List<Attachment>> AttachMap = new Map<Id,List<Attachment>>([
select id,(select id from attachments) from case]);
But i receive the error:
Invalid initial type List<Case> for Map<Id,List<Attachment>>.
How can i get the Map and after the list of Attachment based on case Id. Please help me
Map<Id, List<Attachment>> AttachMap = new Map<Id,List<Attachment>>([
select id,(select id from attachments) from case]);
But i receive the error:
Invalid initial type List<Case> for Map<Id,List<Attachment>>.
How can i get the Map and after the list of Attachment based on case Id. Please help me
You are quering on Case and this query return the following map :
Map<id,Case> caseMap = new Map<Id,case>([select id,(select id from attachments) from case]);
And for your requirment of AttachmentMap you can use following code :
Map<Id, List<Attachment>> AttachMap = new Map<Id,List<Attachment>>();
for(Case cs: [select id,(select id from attachments) from case]){
AttachMap.put(cs.id,cs.attachments);
}
Thanks.
All Answers
You are quering on Case and this query return the following map :
Map<id,Case> caseMap = new Map<Id,case>([select id,(select id from attachments) from case]);
And for your requirment of AttachmentMap you can use following code :
Map<Id, List<Attachment>> AttachMap = new Map<Id,List<Attachment>>();
for(Case cs: [select id,(select id from attachments) from case]){
AttachMap.put(cs.id,cs.attachments);
}
Thanks.