1

I'm trying to create a vf page that creates records based on the records that are selected in the list view. So I created an extension that uses the standard set controller and am using html tags in order to have proper lightning design styling.

VF Page

<apex:page standardController="Contact" extensions="ContactMassSendSurveyController" recordSetVar="contacts" showHeader="false" standardStylesheets="false">

    <apex:slds />  


    <apex:form styleClass="slds-p-around--medium"> 
    <script type="text/javascript">

    // submitForm() is called with the button at the bottom of the page
    function submitForm() {
        sendSurvey(
            document.getElementById("selectedSurvey").options[document.getElementById("selectedSurvey").selectedIndex].value

        );
        console.log(document.getElementById("selectedSurvey").options[document.getElementById("selectedSurvey").selectedIndex].value);
    }                  
    </script>   

    <apex:actionFunction name="sendSurvey" action="{!sendSurveys}">
        <apex:param name="firstParam" value=""/>
    </apex:actionFunction>   

    <div class="slds-scope">
        <div class="slds-grid slds-wrap slds-size_3-of-7">
            <main class="slds-col slds-size--1-of-1 slds-small-size--1-of-2 slds-medium-size--8-of-12 slds-large-size--4-of-5">        

                    <div class="slds-form-element">
                        <label class="slds-form-element__label" for="select-01">Select A Survey</label>
                        <div class="slds-form-element__control">
                            <div class="slds-select_container">        
                                <select id="selectedSurvey" class="slds-select">
                                    <apex:repeat value="{!surveys}" var="survey">
                                        <option value="{!survey.value}">{!survey.label}</option>
                                    </apex:repeat>
                                </select>   
                            </div>
                        </div>
                    </div>   


                <button onclick="submitForm(); return false;">Send Survey</button>
            </main>
        </div>
    </div>

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

Extension

public with sharing class ContactMassSendSurveyController 
{    
    private ApexPages.StandardSetController standardController;

    // constructor.
    public ContactMassSendSurveyController(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }

    // get a list of surveys for the form picklist
    public List<SelectOption> getSurveys() {
        List<SelectOption> surveys = new List<SelectOption>();
        for (SEO__CSEO_Survey__c s : [SELECT Id, Name FROM SEO__CSEO_Survey__c])
        {
            surveys.add(new SelectOption(s.Id , s.Name));
        }

        return surveys;
    } 

    public PageReference sendSurveys()
    {       

        List<Contact> selectedContacts = (List<Contact>) standardController.getSelected();

        String selectedSurvey = Apexpages.currentPage().getParameters().get('selectedSurvey');


        System.debug(selectedSurvey);


        return standardController.cancel();   
    }
}

The debug statement at the end of the controller returns null and I'm not sure why my form isn't sending the selected picklist value to the controller.

1
  • the name of the param needs to be the same as what is being used in Apexpages.currentPage().getParameters().get('paramName') ?
    – Tyler Zika
    Jul 18, 2017 at 17:26

1 Answer 1

2

You named the parameter firstParam, so that's what you need to retrieve:

String selectedSurvey = Apexpages.currentPage().getParameters().get('firstParam'); 

EDIT: I also just noticed that you didn't reRender the page. If you don't do this, the parameters won't be supported.

<apex:actionFunction name="sendSurvey" action="{!sendSurveys}" reRender="">
    <apex:param name="firstParam" value=""/>
</apex:actionFunction>   
5
  • I'm still getting null. Could it be because I'm using a standardSetController?
    – Tyler Zika
    Jul 18, 2017 at 17:32
  • @TylerZika the controller has nothing to do with it. That said, you're doing this in the most complicated way possible. Far easier to just use apex:selectList. I'm mobile so I can't write a full mockup right now, but I'll get back soon as I can.
    – sfdcfox
    Jul 18, 2017 at 17:34
  • The reason I'm doing it this way is to get lightning design styling. I've tried applying the slds class to an apex:selectList and it didn't work.
    – Tyler Zika
    Jul 18, 2017 at 18:16
  • @TylerZika It's possible to do that (and that's really the question you should have asked). That said, I updated my answer with more information; there was another piece that you needed to do that I missed.
    – sfdcfox
    Jul 18, 2017 at 19:05
  • that did it! reRender is needed.....
    – Tyler Zika
    Jul 18, 2017 at 19:20

You must log in to answer this question.

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