I have a weird situation here where I've got a list of Contacts in a wrapper which has checkboxes, allowing users to process these records. These Contacts are obtained by a getting a query from the URL.
E.g. salesforce.com/apex/MyApp?Id=003D123,003D456,003789
I've got a function called removeSelected which modifys the URL and removes Ids, works great, a function called prescreenSelected which sends the Ids to another VisualForce page, works great, and a function called createApplication which creates an application, works great.
The problem comes from having these all in an Apex:Form and the fact the LookUp is a required field. Although the only function that uses the LookUp is createApplication, it's being processed and throwing a validation error when another function is used.
My VisualForce page looks like this below:
<apex:form>
<div class="row">
<div class="col-md-4">
<apex:commandButton styleClass="btn btn-default form-control" value="Remove Selected" action="{!removeSelected}" />
</div>
<div class="col-md-4">
<apex:commandButton styleClass="btn btn-default form-control" value="Prescreen Selected" action="{!prescreenSelected}" reRender="redirectpanel" oncomplete="redirect()" /
</div>
<div class="col-md-4">
<apex:inputField styleClass="form-control" id="candidate" value="{!applicationLookup.ts2__Job__c}" />
<apex:commandButton styleClass="btn btn-default form-control" value="Create Application(s)" action="{!createApplications}" />
</div>
<apex:pageBlock>
<apex:pageBlockTable value="{!contacts}" var="c">
<apex:column>
<apex:inputCheckbox value="{!c.selected}" />
</apex:column>
<apex:column value="{!c.con.FirstName} {!c.con.LastName}" />
<apex:column value="{!c.con.Phone}" />
<apex:column value="{!c.con.MobilePhone}" />
<apex:column value="{!c.con.EMail}" />
</apex:pageBlockTable>
</apex:pageBlock>
</div>
</apex:form>
I'm guessing the VisualForce page is still posting the LookUp even though it's not used in two of the three functions and thus is still being processed for validation.
I've tried:
- Using two Apex Forms to seperate the LookUp and createApplication button from the other two functions, but this renders them useless as they can't then get what's been selected in the list
- Wrapping the buttons within an Apex:ActionRegion, but this seems to have no effect
- Other horrible hacky things
Genuinely stuck on how to handle this one. Any help would be massively appreciated.