You need to sign in to do that
Don't have an account?

question on getting map field values
Hi,
I have code below, I wish to know how to get value of individual fields instead of using it like values() from map.
CODE:
for(Case c:caseemlist) {
for(EmailMessage em:c.EmailMessages) {
Emailmessage message = new Emailmessage (fromname = em.fromname,subject = em.subject,textbody = em.textbody,htmlbody = em.htmlbody,toaddress = em.toaddress,
fromaddress = em.fromaddress,ccaddress = em.ccaddress,status = em.status,messagedate = em.messagedate,ParentId=oldnewCaseIdmap.get(c.id));
//emlisttoinsert.add(message);
emailMessageMap.put(em.Id, message);
}
}
Attachment[] attList = new list <Attachment>();
Attachment[] insertAttList = new list <Attachment>();
if(emailMessageMap.values().size()>0) {
insert emailMessageMap.values();
Example in above, i wsh to insert individual values like fromaddress, ccaddress, how do i do it, i dont want to use values().
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_map.htm
for(Emailmessage message : emailMessageMap.values()) {
insert message;
}
Definitely, inserting data in loop is very bad practice. As the question was how to get data from map, that I answered. Insertion should be always in the list to handle governor limit.
EmailMessage eMsg = emailMessageMap.get(em.Id);
or
EmailMessage eMsg = emailMessageMap.get(id);
also doesnt work
em.id is very issue is, how do we get values from this map?
for(Emailmessage message : emailMessageMap.values()) {
System.debug('Message:::::' + message);
}
system.debug(emailMessageMap.values());
AND IT SHOWS THIS
13:33:15:085 USER_DEBUG [40]|DEBUG|(EmailMessage:{Status=0, ParentId=500J0000001IBG7IAO, Subject=RE: YellowBook Escalation call to sync up, HtmlBody=<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsof
THIS STATEMENT IS BAD
insert emailMessageMap.values();
its causing heapsize to increase a lot, which is why we see the issue, i want to control that.
THIS
emailMessageMap.put(em.Id, message);
}
}
if(emailMessageMap.values().size()>0) {
for(Emailmessage message : emailMessageMap.values()) {
System.debug('Message:::::' + message);
}
however i realized how to get individual values from map, which was doing the for loop again getting value using id and it worked.
thanks