3

So I have an odd issue where I have two apex:apex:commandButtons on the same page. One load's some data, and the other creates a new task. The new task action works great, but the load data button can't actually submit because the task generates an error since it's not populated.

First Button

<apex:commandButton id="getData" action="{!getData}" value="Get Values" />

Second Button and Info:

<apex:pageBlock id="taskInfo" title="Task Information">
    <apex:pageBlockSection columns="2">
        <apex:inputField label="Assigned To:" value="{!task.OwnerId} "/>
        <apex:inputField label="Subject:" value="{!task.Subject} "/>
        <apex:inputField label="Status:" value="{!task.Status} "/>
        <apex:inputField label="Priority:" value="{!task.Priority} "/>
    </apex:pageBlockSection>
</apex:pageBlock>

<apex:commandButton action="{!addTasks}" value="Add Tasks" />

So the first button can't submit correctly because the page will return an error than says values must be entered for the required fields for the task.

Is there a way to isolate the first button from "submitting" the task?

EDIT: I can't believe I didn't think of this, but all I had to do was to separate them into two apex:form elements. Thanks for all the responses!

2
  • It would be helpful if we either see the page code or a screen capture of the page to know what data the button was getting. Although its possible it doesn't have the user reference. I'm not up on my button code to know what's missing.
    – crmprogdev
    Jun 20 '14 at 16:23
  • did you try immediate="true" on the first button?
    – cropredy
    Jun 20 '14 at 17:50
2

You need to use an ActionRegion tag to isolate the 2 different form submissions from each other. Wrap each of the command buttons and the form sections to submit in an ActionRegion tag pair.

<apex:form>
<apex:actionRegion>
<apex:pageBlock id="taskInfo" title="Task Information">
<apex:pageBlockSection columns="2">
    <apex:inputField label="Assigned To:" value="{!task.OwnerId} "/>
    <apex:inputField label="Subject:" value="{!task.Subject} "/>
    <apex:inputField label="Status:" value="{!task.Status} "/>
    <apex:inputField label="Priority:" value="{!task.Priority} "/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:commandButton action="{!addTasks}" value="Add Tasks" />e
</apex:actionRegion>
<apex:actionRegion>
 //other stuff and button
</apex:actionRegion>
</apex:form>

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.