0

hoping for some guidance on how i can accomplish something in VF. Basically i have 2 SelectLists side by side where the left one contains a list of all SFDC users in my instance and the right one contains my selected users after the end user presses a button to add it to that list. I'm saving the selected users in a custom object to be used to send notifications to those users when my app finishes a task.

The problem i'm running into is that above this, i've got several fields that are set to required in the field definition and so the commandButtons keep triggering those. I'm not saving anything at this point, i just want to call a controller method to add users to the other selectList without hitting validation errors. I've tried actionFunction, actionRegion, immediate=true, and none of them seem to work. Any ideas on how i can use a controller function to affect the data on the VF page without all the validation triggers blocking the call?

SelectList section of VF Page:

  <apex:pageBlockSection title="Email Notifications" columns="4" id="pbsectionemail">
    <apex:pageBlockSectionItem id="pbsectionemlchkbx">
        <apex:outputpanel style="float:left;">
                        <apex:inputCheckBox id="emlchkbx" value="{!emailCheck}" style="margin-top:0;" />
                        <apex:outputLabel style="display:contents;white-space:nowrap;">Email Notifications </apex:outputLabel>
        </apex:outputpanel>
    </apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem id="pbsectionemlallusers">    
        <apex:selectList id="EmailAllUsers" size="5" styleClass="sList" multiselect="true" value="{!selectedSFEmailUsers}">
            <apex:selectOptions value="{!sfnonemailusers}" />
        </apex:selectList>
    </apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem id="pbsectionemlbuttons">
        <apex:outputpanel >
            <table style="text-align:center;">
                <tr><td>
                    <apex:commandButton value=">" id="emlbtngt" onclick="addEmlUsers" style="background:#EFEFEF;border-color:#646464;border-width:1px;height:50px;width:50px;" />
                    <apex:actionSupport event="onclick" action="{!addEmailUsers}" reRender="EmailAllUsers, EmailSelectedUsers" />
                </td></tr>
                <tr><td>
                    <apex:commandButton value="<" id="emlbtnlt" onclick="remEmlUsers" style="background:#EFEFEF;border-color:#646464;border-width:1px;height:50px;width:50px;" />
                    <apex:actionSupport event="onclick" action="{!removeEmailUsers}" reRender="EmailAllUsers, EmailSelectedUsers" />
                </td></tr>
            </table>        
        </apex:outputpanel>
    </apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem id="pbsectionemlselectusers">    
        <apex:selectList id="EmailSelectedUsers" size="5" styleClass="sList" multiselect="true" value="{!selectedLBEmailUsers}">
            <apex:selectOptions value="{!lbemailusers}" />
        </apex:selectList>
    </apex:pageBlockSectionItem>
    </apex:pageBlockSection>

Snippets of the Controller Extension:

    public List<SelectOption> lbbellusers{ get; private set; }
{
    lbbellusers = new List<SelectOption>();
    User[] users = [Select Id, Name from User WHERE ID IN :setbelluserIDs ORDER BY Name];
    for (User u: users)
    {
        lbbellusers.add(new SelectOption(u.Id,u.Name));
    }
}
public List<SelectOption> lbemailusers{ get; private set; }
{
    lbemailusers = new List<SelectOption>();
    User[] users = [Select Id, Name from User WHERE ID IN :setemailuserIDs ORDER BY Name];
    for (User u: users)
    {
        lbemailusers.add(new SelectOption(u.Id,u.Name));
    }
}
public List<SelectOption> sfnonbellusers{ get; private set; }
{
    sfnonbellusers = new List<SelectOption>();
    User[] users = [Select Id, Name from User WHERE IsActive = true AND ID NOT IN :setbelluserIDs ORDER BY Name];
    for (User u: users)
    {
        sfnonbellusers.add(new SelectOption(u.Id,u.Name));
    }
}
public List<SelectOption> sfnonemailusers{ get; private set; }
{
    sfnonemailusers = new List<SelectOption>();
    User[] users = [Select Id, Name from User WHERE IsActive = true AND ID NOT IN :setemailuserIDs ORDER BY Name];
    for (User u: users)
    {
        sfnonemailusers.add(new SelectOption(u.Id,u.Name));
    }
}

public void addBellUsers()
{
    for(String s:selectedSFBellUsers )
    {
        SelectOption so = new SelectOption(s, userLabels.get(s));
        lbbellusers.add(new SelectOption(s, userLabels.get(s)));
        integer index = sfnonbellusers.indexOf(so);
        sfnonbellusers.remove(index);
    }
}
public void addEmailUsers()
{
    for(String s:selectedSFEmailUsers )
    {
        SelectOption so = new SelectOption(s, userLabels.get(s));
        lbemailusers.add(new SelectOption(s, userLabels.get(s)));
        integer index = sfnonemailusers.indexOf(so);
        sfnonemailusers.remove(index);
    }
}
public void removeBellUsers()
{
    for(String s:selectedLBBellUsers )
    {
        SelectOption so = new SelectOption(s, userLabels.get(s));
        sfnonbellusers.add(new SelectOption(s, userLabels.get(s)));
        integer index = lbbellusers.indexOf(so);
        lbbellusers.remove(index);
    }
}
public void removeEmailUsers()
{
    for(String s:selectedLBEmailUsers )
    {
        SelectOption so = new SelectOption(s, userLabels.get(s));
        sfnonemailusers.add(new SelectOption(s, userLabels.get(s)));
        integer index = lbemailusers.indexOf(so);
        lbemailusers.remove(index);
    }
}
3
  • I'm exploring the option of using a second form in the page just for the selectlists as i've heard that can be a workaround although i believe this is bad practice so i'm hoping it can be resolved without resorting to that. Thanks again!
    – Shane
    Aug 4 '20 at 20:56
  • 2
    Actually i figured it out. removed the html-5 doctype and used actionregion and this resolved the issue. Looks like it was html5 that was causing an added layer of validation i even when actionregion was being used. Quick fix...don't use html5 for now.. :)
    – Shane
    Aug 4 '20 at 23:03
  • pls post it as an answer, so the next time some one comes up with same issue, he can find the answer immediately.
    – Ysr Shk
    Aug 5 '20 at 2:58
0

i figured it out. removed the html-5 doctype and used actionregion and this resolved the issue. Looks like it was html5 that was causing an added layer of validation i even when actionregion was being used. Quick fix...don't use html5 for now.

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.