function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mano sfdcMano sfdc 

I need Radio Buttons instead of checkboxes in below code

Hi All,

Page Code:

<apex:page controller="Send_Doc_Controller" >
  <apex:sectionHeader title="Documents" subtitle="Email a Document" 
    description="email existing document to specified email address"/>

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

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

      <apex:pageBlockSection >

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

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

      </apex:pageBlockSection>

      <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>
      </apex:pageBlockSection>

    </apex:pageBlock>
  </apex:form>
</apex:page>


Class Code:

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;
    }
    set;
  }

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

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

      system.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'+doc);

    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    attach.setContentType(doc.contentType);
    attach.setFileName(doc.developerName+'.'+doc.type);
    attach.setInline(false);
    attach.Body = doc.Body;

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

    s = email.split(',');
    system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+s);
    mail.setToAddresses(s);
    system.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'+string.valueof(s));
    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;
  }
}


Note: in documents, need at least two documents.

 
ShashankShashank (Salesforce Developers) 
You should be using "apex:selectradio" instead of "apex:selectlist" to get radio buttons. Please see this: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectRadio.htm