3

I have a VF page which has a Save and cancel button and i am using this page on Sites.

The issue that i have is Whenever there is a validation like a Required field is not entered then an apex:message is shown that value is required. But after that the parameters in the url is lost.

For example

If the url of the VF page is http://abc-developer-edition.ap1.force.com/Candidate?jobId=a039000000jc8koAAA

after the validation error url changes to http://abc-developer-edition.ap1.force.com/Candidate

(It removes the parameters)

<apex:commandButton action="{!SaveResult}" value="Submit" styleclass="btn btn-primary"/>

SaveResult is a controller method where i save the record. Everything works fine when all the values are entered correct.

I am using the required in VF page this way.

<apex:inputField value="{!field_disp[f.fieldPath]}" required="{!OR(f.required, f.dbrequired)}"  styleClass="form-control"/>

Any thoughts what could be causing this?

Thanks

  • what does your SaveResult method returns? – tugce Sep 22 '16 at 14:46
  • It returns a page reference. Thats not the issue. It works fine with all values correctly fed in. The validation are on client side (i assume) because i have required="true" in apex:inputField – Prady Sep 22 '16 at 15:00
4

If you don't put a rerender in the commandbutton, it will rerender the entire page if null is returned from the SaveResult method. And it rerenders the page without the page parameters. I guess the same happens for the required="true" parameter.

When I had this problem I added rerender="[some id of e.g. the form]" to the commandbutton, which made it work fine because it will only rerender that part and leave the url as it is.

  • mmm.. interesting. I have a Apex:inputFile in my form which is resulting in an error commandLink that specifies a rerender or oncomplete attribute. – Prady Sep 22 '16 at 16:43
  • apex:inputFile tag does not allow you to use any other tag specifying rerender attribute in the same form. Either you need use IFrame strategy something like this (github.com/Katulka/SalesforceIframeInputFile) or use the @RemoteAction way by reading the file contents using js and sending over to controller. Good Luck! – javanoob Sep 22 '16 at 17:28
  • 1
    apex:inputfile... Bad news :-) As an alternative to javanoob's methods you could also consider replacing the 'required' tag with just the required markup and doing the validation (+ possibly an error) in your controller. See an example here: salesforce.stackexchange.com/questions/2108/… – Guy Clairbois Sep 22 '16 at 20:06
1

Salesforce strips all the parameters except for id (lowercase only!, Id or ID will also be removed) for the action attribute of the HTML form tag. Any command button will send a POST request to this address, so if no redirect is performed you will stay there.

The obvious suggestion is to only use id parameter and grab all other info from database (or serialize all your parameters into one id string in extreme cases).

  • This seems to be correct, all params get stripped except for id – Prady Sep 27 '17 at 15:37

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.