You need to sign in to do that
Don't have an account?
Carter85
Help with a select list issue
I have an odd problem I'm trying to fix. I have a page in which I'm trying to display a multi-select list of options from a user to choose from:
Here's the controller:
<apex:page Standardcontroller="Case" extensions="CM_URCaseEmailer" sidebar="false" showheader="false" cache="false" expires="0" standardStylesheets="false"> <apex:messages /> <apex:pageBlock title="Send an email regarding Case # {!cseNum}" rendered="{!EMAIL}"> <apex:form > <apex:outputText>Select the team members to send the message to:</apex:outputText><br/> <apex:selectList style="width:500px" value="{!addresses}" multiselect="true" size="10" > <apex:selectOptions value="{!options}"/> </apex:selectList> <br/><br/> <apex:outputLabel value="Subject" for="Subject"/>:<br/> <apex:outputText value="{!subject}" id="Subject"/> <br/><br/> <apex:outputLabel value="Body" for="Body"/>:<br/> <apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/> <br/><br/><br/> <apex:commandButton value="Preview Email" action="{!preview}"/> <br/> <br/> <apex:outputLabel value="Attach a File"/>:<br/> <apex:panelGroup > <script type = "text/javascript"> function check(obj) { var path = obj.value; var ext = path.substring(path.lastIndexOf('.') + 1); if(obj.size > 10240){ obj.value = null; window.alert("File size can not exceed 10MB."); return false; } var res_field = obj.value; var extension = res_field.substr(res_field.lastIndexOf('.') + 1).toLowerCase(); var allowedExtensions = ['jpg', 'jpeg', 'tif', 'pdf', 'png', 'txt', 'doc', 'docx']; if (res_field.length > 0){ if (allowedExtensions.indexOf(extension) === -1){ alert('Invalid file Format. Only ' + allowedExtensions.join(', ') + ' are allowed.'); obj.value = null; return false; } } } </script> <apex:inputFile id="upload" accept="txt, jpg, jpeg, tif, png, doc, docx, pdf" onchange="check(this)" filename="{!fileName}" contentType="{!contentType}" filesize="1000" size="50" value="{!file}"/> </apex:panelGroup> </apex:form> </apex:pageBlock> </apex:page>However, even though I have verified with my debug logs that the list should be populating during my tests it renders only as blank.
Here's the controller:
public with sharing class CM_URCaseEmailer { public String[] addresses {get;set;} public String subject {get;set;} public String body {get;set;} public Boolean EMAIL {get;set;} public Blob file {get;set;} public string fileName {get;set;} public String contentType {get; set;} private static String displayName = 'do-not-reply@donotreply.com'; private static String replyEmail = 'do-not-reply@donotreply.com'; public List<Case> cse {get;set;} public List<CaseTeamMember> team {get;set;} public List<Contact> cTeam {get;set;} public List<User> uTeam {get;set;} public List<SelectOption> options {get;set;} public List<ID> idLst {get;set;} public String cseNum {get;set;} // Create a constructor that populates the Issue object public CM_URCaseEmailer(ApexPages.StandardController controller){ addresses = new String[]{}; getItems(); cseNum = cse[0].CaseNumber; subject = 'Information regarding open Case # ' + cseNum; EMAIL = true; } public List<SelectOption> getItems(){ cse = [SELECT ID, CaseNumber FROM Case WHERE id =:ApexPages.currentPage().getParameters().get('id')]; team = new List<CaseTeamMember>(); team = [SELECT MemberID FROM CaseTeamMember WHERE Parent.ID =: cse[0].ID]; List<ID> idLst = new List<ID>(); for(integer t = 0; t < team.size(); t++){ idLst.add(team[t].MemberID); } cTeam = new List<Contact>(); uTeam = new List<User>(); cTeam = [SELECT ID, Name, Email FROM Contact WHERE ID IN: idLst]; uTeam = [SELECT ID, Name, Email FROM User WHERE ID IN: idLst]; List<SelectOption> options = new List<SelectOption>(); if(cTeam.size() > 0){ for(integer q = 0; q < cTeam.size(); q++){ options.add(new SelectOption(cTeam[q].Email,cTeam[q].Name)); } } if(uTeam.size() > 0){ for(integer r = 0; r < uTeam.size(); r++){ options.add(new SelectOption(uTeam[r].Email,cTeam[r].Name)); } } system.debug('Team: ' + team); system.debug('ID: ' + idLst); system.debug('Contact: ' + cTeam); system.debug('User: ' + uTeam); system.debug('Options: ' + options); return options; } public String[] getAddresses(){ return addresses; } public PageReference preview(){ getAddresses(); return page.CM_PreviewMessage; } public PageReference back(){ return page.CM_ClaimEmailConvo; } public PageReference send(){ // Define the email Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); //String address = cse[0].Contact_Email__c; //String[] toAddress = address.split(':', 0); //if(cse[0].Contact_Email__c != null){ // Sets the paramaters of the email email.setSubject(subject); //email.setToAddresses(toAddress); email.setHtmlBody('<p>' + body + '</p>' + ' Please do not reply directly to this email, the address which sent this message is not monitored. To send a reply regarding your claim, click the following link: "mailto:email_to_issue@7y00nkwgarhuofryox60fppai5gbe09bl5th5np38g3ud4x78.19-ddlxeao.cs24.apex.sandbox.salesforce.com?subject=Re: Information regarding open issue with Maximus Auto Group # '+csenum+'"'); email.setSenderDisplayName(displayName); email.setReplyTo(replyEmail); file = file; if(file != null){ Attachment attach = new Attachment(); attach.Body = file; attach.Name = filename; attach.ContentType = contentType; attach.ParentID = cse[0].ID; Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName(filename); efa.setBody(file); email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); } // Sends the email Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); // Create and insert a new Task Task task = new Task(ActivityDate = Date.today(), CallDisposition = 'Email Sent to Customer', CallType = 'Outbound', Description = email.HTMLBody.stripHTMLTags() + ' Files attached: ' + filename, Status = 'Completed', // Subject = 'Email to: ' + toAddress, Type = 'Email', WhatId = cse[0].ID); insert task; return null; //} return null; } }Any suggestions would be appreciated.