+ Start a Discussion
bozotheclownbozotheclown 

ActionFunction and Order of Execution

Hello.  I was wondering if someone could give me some guidance.  I am pretty sure this is an order of execution issue as it relates to using an action function/dynamic component

I am having problems with how an action function acts after error messages.

The below code is a simple process we have for saving a shipment status.  We use a button tied to an action function on the page to populate the "FieldA".

SCENARIO 1
I populate the status field and press the actionfunction button...then "Save".  All works fine - as I next see the myPage.

SCENARIO 2
I manually check the status__c field...then "Save".  All works fine - as I next see the myPage.

SECENARIO 3
I forget to populate the status__c field (by clicking the button or manually)...and I press the "save" button.  I receive an error message.  I then go back to the status__c picklist field..and all works fine - as I next see the myPage.

SECENARIO 4
I forget to populate the status__c field...and I press the "save" button.  I receive an error message.  HOWEVER, this time i press the button tied to the action function...then I press the "save" button.  Strangely,  I  am then prompted with my override message.  That should not be happening.

Long story short, pressing the actionfunction button after the error message is displayed prevents the status__c field to be properly read.

Any suggestions on how I can pass the status__c value after pressing the button (after the error is displayed)?

I do know the code works...so the problem is specifically between an error message display, an action function and rerendering...my research leads me to beleive that this is an order of execution issue.

Thanks in advance.

public PageReference save() {


if(Status__c<>null)  // The field is populated by either a picklist or by a button tied to an action function - the problem happens when the button is pressed after an error message is displayed
//  
{
orderok__c = true;
NoMgtReviewNeeded = true;
}
ELSE
{
error=true;
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No status.  Revise.'));
}

if(error<>true)
{

if(NoMgtApprovalNeeded==true)
{
insert aaa;
return myPage;
}
ELSE
{
return null;
}

ELSE
{
return null;
}

}

VF
<apex:commandButton action="{!save}" value="Save""/>
<br/>
<apex:outputText value="A 'Manager Override' is required!" rendered="{!NoMgtApprovalNeeded=false && aaa.orderok__c=true}"/>
<br/>
<br/>
<apex:commandButton action="{!Override}" value="Manager Override" rendered="{!NoMgtApprovalNeeded=false && aaa.orderok__c=true}"/>


PrasanntaPrasannta (Salesforce Developers) 
Hi

Please refer to the link below to know about the order of execution works-

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm

https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle.htm

Hope this helps.