0

I have two picklists in a vf page, based on first picklist value i need to render second picklist, after rendering based on selected value in second pick list i need to send the email, but i am unable to get the selected value in second picklist to the controller to process it, following is my full code.

public class ProviderContactUs {


    public List<Group> GroupNameList  = new List<Group>(); 
 public ContactUs__c contact;
 public String subject {set;get;}
 public string body {set;get;}
    public string queueName{set;get;} 
    public string subqueue1{set;get;}
    public string options{set;get;}


    // Create a constructor that populates the Account object
    public ProviderContactUs (ApexPages.StandardController controller) {}
    public List<SelectOption> QueueList 
    {
        get
        {
            GroupNameList  = [select  g.Email,g.Name from Group g where Type = 'Queue' and DeveloperName like 'HA_%'];

            QueueList = new List<SelectOption>();

            for(Group temp : GroupNameList)
            {
                QueueList.add(new SelectOption(temp.Email, temp.Name));
            }
                         return QueueList;
        }
        set;


    } 


    public Attachment attachment 
    {
        get
        {
            if (attachment == null)
            attachment = new Attachment();
            return attachment;
        }
        set;
    }


    public PageReference save() {

        system.debug('queueName### '+queueName);
        system.debug('subqueue### '+subqueue1);



        if(queueName == '100')
        {
            queueName = subqueue1;
        }


        boolean isAttachment = false;
        if(attachment!=null && attachment.Name!=null)
        {
            isAttachment = true;
        }


        if(isAttachment){
         contact= new ContactUs__c(name = attachment.Name, subject__C = subject, body__C = body);
        insert contact;
        attachment.OwnerId = UserInfo.getUserId();
        attachment.ParentId = contact.Id;
        attachment.IsPrivate = false;

        insert attachment;   
        }


        //Start: Send Email with Attachment
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[]{queueName, subqueue1};


            mail.setToAddresses(toAddresses);
            mail.setSubject(subject);
            mail.setPlainTextBody(body);

          if(isAttachment){
                 //Set email file attachments
            List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();

            // Add to attachment file list

            Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
            efa.setFileName(attachment.Name);
            efa.setBody(attachment.Body);
            fileAttachments.add(efa);


            mail.setFileAttachments(fileAttachments);

          }

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

            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));    
           // ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'Error: Unable to upload the attachment.'));

            return null;

    }

VF Page:

 <apex:form >
        <apex:pageBlock id="pb1">
            <apex:outputText value="Category" style="font-weight:900" /> &nbsp;

                <apex:selectList value="{!queueName}" size="1" id="first" >
                         <apex:selectOption itemLabel="--None--" itemValue=""/>
                        <apex:selectOptions value="{!QueueList}"/>
                        <apex:selectOption itemLabel="Event/Client Info" itemValue="1"/>
                        <apex:selectOption itemLabel="Afterhours Emergencies" itemValue="2"/>
                        <apex:selectOption itemLabel="Staffing or Travel" itemValue="100"/>
                        <apex:actionSupport event="onchange" rerender="pb"/> 
                </apex:selectList>

            </apex:pageBlock>


            <apex:outputPanel id="pb" >
        <apex:pageBlock rendered="{!queueName='100'}">
                <apex:pageBlockSection  >
                    <apex:outputText value="Please select your staffing Coordinator" style="font-weight:900" /> &nbsp;

                <apex:selectList value="{!subqueue1}"  size="1" id="second">
                    <!-- <apex:selectOptions value="{!Items}"/> -->
                    <apex:selectOption itemLabel="Jessica Koponen" itemValue="[email protected]"/>
                    <apex:selectOption itemLabel="Carmella Ramirez" itemValue="[email protected]"/>
                        <apex:selectOption itemLabel="June Thai" itemValue="[email protected]"/>
                        <apex:selectOption itemLabel="Mary Casillas" itemValue="[email protected]"/>
                        <apex:selectOption itemLabel="I don’t know" itemValue="[email protected]"/> 
                </apex:selectList>

                </apex:pageBlockSection>

                <apex:pageBlockSection id="sub2" rendered="{!queueName='1'}">
                    <apex:outputText value="Please email the Project Manager listed on your detail sheet" style="font-weight:800"/>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="sub3" rendered="{!queueName='2'}">
                    <apex:outputText value="Please call 484-567-0827"  style="font-weight:800"/>
                </apex:pageBlockSection>

        </apex:pageBlock>
  </apex:outputPanel>

        </apex:form>

Please help me guys, Thanks in advance...

1 Answer 1

0

The id of the output Panel which you want to reRender is wrong.

Correct code snippet

<apex:form >
    <apex:pageBlock id="PageBlock">
        <apex:outputText value="Category" style="font-weight:900" /> &nbsp;
            <apex:selectList value="{!queueName}" size="1" id="first" >
                    <apex:selectOption itemLabel="--None--" itemValue=""/>
                    <apex:selectOptions value="{!QueueList}"/>
                    <apex:selectOption itemLabel="Event/Client Info" itemValue="1"/>
                    <apex:selectOption itemLabel="Afterhours Emergencies" itemValue="2"/>
                    <apex:selectOption itemLabel="Staffing or Travel" itemValue="100"/>
                    <apex:actionSupport event="onchange" rerender="pb"/> 
            </apex:selectList>
    </apex:pageBlock>

    <apex:outputPanel id="pb">
        <apex:pageBlock rendered="{!queueName == '100'}">>
            <apex:pageBlockSection id="pb1">
                <apex:outputText value="Please select your staffing Coordinator" style="font-weight:900" /> &nbsp;
                <apex:selectList value="{!subqueue1}"  size="1" id="second">
                    <apex:selectOption itemLabel="Jessica Koponen" itemValue="[email protected]"/>
                    <apex:selectOption itemLabel="Carmella Ramirez" itemValue="[email protected]"/>
                    <apex:selectOption itemLabel="June Thai" itemValue="[email protected]"/>
                    <apex:selectOption itemLabel="Mary Casillas" itemValue="[email protected]"/>
                    <apex:selectOption itemLabel="I don’t know" itemValue="[email protected]"/> 
                </apex:selectList>
            </apex:pageBlockSection>

            <apex:pageBlockSection id="sub2" rendered="{!queueName == '1'}">
                <apex:outputText value="Please email the Project Manager listed on your detail sheet" style="font-weight:800"/>
            </apex:pageBlockSection>

            <apex:pageBlockSection id="sub3" rendered="{!queueName == '2'}">
                <apex:outputText value="Please call 484-567-0827"  style="font-weight:800"/>
            </apex:pageBlockSection>

        </apex:pageBlock>
    </apex:outputPanel>
 </apex:form>

Try this out and let me know if it helps.

9
  • Thanks for your response,But this also not working Ankita, do you have any other workarounds? Commented Jul 10, 2017 at 9:48
  • Can you add any screenshot of the VF page?
    – Ankita
    Commented Jul 10, 2017 at 10:05
  • i am unable to add a screenshot here, so copied the fresh code to my question Commented Jul 10, 2017 at 10:15
  • I have updated the code. Try it and let me know if it helps
    – Ankita
    Commented Jul 10, 2017 at 10:19
  • this code throwing a error, Duplicate ids have been detected: 'j_id0:j_id15:pb' Commented Jul 10, 2017 at 10:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .