Hi everyone i want to send multiple attachment through mail. So i created a checkbox to select the required document and send them but it is throwing this error

"Conversion Error setting value '01590000004fxbiAAA' for '#{documentId}'."

Please guide me how to fix it.


public with sharing class Send_Doc_Controller {
    // public ID documentId {get;set;}
    Public List<Id> documentId {get;set;}
    public String email {get;set;}
    public string[] s = new string[]{};

      public List<SelectOption> documents {
    get {
            documents = new List<SelectOption>();
            for(Document d : [SELECT id,Name FROM Document ]){
                Documents.add(new SelectOption(d.Id,d.name));
            return documents;

  public PageReference sendDoc(){
          Document doc = [select id, name, body, contenttype, developername, type 
      from Document where id IN: documentId];


    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    attach.Body = doc.Body;

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

    s = email.split(',');
    mail.setSubject('Document Email Demo');
    mail.setHtmlBody('Here is the email you requested: '+doc.name);
    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); 

    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with Document sent to '+email));

    return null;

My VF Page

<apex:page controller="Send_Doc_Controller" >
  <apex:sectionHeader title="Document Example" subtitle="Email a Document" 
    description="Example of how to email a Document."/>

  <apex:form >
    <apex:pageMessages />
    <apex:pageBlock title="Document Input">

      <apex:pageBlockButtons >
        <apex:commandButton action="{!sendDoc}" value="Send Document"/>

      <apex:pageBlockSection >

        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Email to send to" for="email"/>
          <apex:inputText value="{!email}" id="email"/>

     <!--   <apex:pageBlockSectionItem >
            <apex:outputLabel value="Document" for="document"/>
            <apex:selectList value="{!documentId}" id="document" size="1">
                 <apex:selectOptions value="{!documents}"/>
        </apex:pageBlockSectionItem> -->


      <apex:pageBlockSection title="Select Documents" columns="2" >
          <apex:selectCheckboxes layout="pageDirection"  borderVisible="true" value="{!documentId}" id="document" legendInvisible="false"><apex:selectoptions value="{!documents}" /></apex:selectCheckboxes>


Add this to controller:

public Send_Doc_Controller(){
    documentId = new List<Id>();

Note that you should always declare variables if you intend to use them later. And make sure you add some other controls; for example: 1) if you didn't choose any document, you shouldn't be making queries and adding them to email, 2) email syntax,..

  • no luck still the same error – Sharat Sep 9 '14 at 12:30
  • I copy pasted your code in my org and added my code and it works like a charm. – ziga Sep 9 '14 at 19:51
  • Please guide me where i can put patch code in controller. Thanks in advance. Thanks, Manohar – user11492 Sep 10 '14 at 5:43
  • Hi Zinga, I was facing same problem your suggestion help me thanks.. When I checked more then one document it failed to sent mail... It show error "Error is in expression '{!sendDoc}' in component <apex:commandButton> in page senddoc: Class.SendDocController.sendDoc: line 21, column 1" – Dilip Mar 11 '15 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.