You need to sign in to do that
Don't have an account?
PageReference not working as expected
I'm trying to gather some information from the user with regards to a lead, and then send them back to a page with a list of leads. The page I'm referencing in my method is not linking properly to the submit button and I'm at a loss as to why. Here is the APEX and VF code. The submit button on the VF page at /reject?id=rep.email&flip={!flip.id} should update three fields on the Lead Record and return the users to the /registrations?id={!rep.email} page. Instead it's not updating the lead and is resetting the page URL to be /reject?id={rep.email}.
I have almost identical code working in another part of this class and am completely stumped why this would be happening. Any clues?
public Contact rep = new Contact(); public String rejectReason{get;set;} public String rejectDetail{get;set;} public Lead flip {get;set;} Public leadView(){ Rep = [SELECT id, FirstName, LastName, Email, Accountid, Account.Type, Shark_Tank_Access__c FROM Contact WHERE email =:ApexPages.currentPage().getParameters().get('id') limit 1]; } public Contact getRep(){ return rep; } public Lead getFlip(){ flip = [SELECT id, Company, FirstName, LastName, Title, Registered_Rep__c, Registered_Rep__r.Email, Lead_Reject_Reason__c, Reject_Reason_Details__c, Rejected_by__c FROM Lead WHERE id =: ApexPages.currentPage().getParameters().get('flip')]; return flip; } public pageReference rejectLead(){ flip.Rejected_by__c = ptnrRep.id; flip.Lead_Reject_Reason__c = rejectReason; flip.Reject_Reason_Details__c = rejectDetail; update flip; pageReference goBack = new pageReference('/apex/registrations?id='+rep.email); goBack.setRedirect(true); return goBack; }
Visual Force Code:
<apex:form > <apex:outputField value="{!flip.Company}"/><p/> <apex:outputField value="{!flip.State}"/><p/> <apex:selectList id="State" value="{!rejectReason}" multiselect="false" size="1" required="True"> <apex:selectOption itemvalue="" itemLabel="--Please Select--"/> <apex:selectOption itemvalue="" itemLabel="Deal In progress"/> <apex:selectOption itemvalue="" itemLabel="End user not willing to engage"/> <apex:selectOption itemvalue="" itemLabel="Information Request Only"/> <apex:selectOption itemvalue="" itemLabel="Invalid contact information"/> <apex:selectOption itemvalue="" itemLabel="Lost to competition"/> <apex:selectOption itemvalue="" itemLabel="Not an end user"/> <apex:selectOption itemvalue="" itemLabel="Project Delayed/Cancelled"/> <apex:selectOption itemvalue="" itemLabel="Unreachable"/> </apex:selectList> <p/> <apex:inputText value="{!rejectDetail}"/> <p/> <apex:commandButton value="Submit" action="{!rejectLead}"/> </apex:form>
I finally solved it, but I couldn't tell you how. I deconstructed the whole thing and added the fields back into the VF page one by one and finally got it working, but honestly, not sure what I did that was different.
All Answers
When I've hit this kind of thing in the past its usually because an error message is being swallowed - do you have an apex:pagemessages component on your page somewhere? If not, I'd try adding one. Given that your itemvalues are empty strings, I'd suspect that the required aspect of the selectlist isn't being satisfied.
Right!!! this seems wired........however its not a surprise to me....
I would suggest you to check with apex:commandLink instead of apex:commandButton..........
seems instead of that method being called your page is just refreshing.
What browser are you using? I had similar issues when using IE8 with Google Chrome Frame.
I finally solved it, but I couldn't tell you how. I deconstructed the whole thing and added the fields back into the VF page one by one and finally got it working, but honestly, not sure what I did that was different.
I just ran into this issue and only by removing components from my VF page and slowly adding them back in until it stopped working again was I able to narrow down the issue. It wasn't happy that I was using apex:inputFields instead of apex:inputTexts. Not sure why they were all referring to object fields. But I swapped them and it worked fine after that. Very strange. I agree with Bob some error message is being swallowed and its resulting in this odd behavior. Perhaps an update to the VF validation is needed.
If any of the inputfields were required, that would stop the page from being submitted back. If the page is utilising rerendering, then the page can appear not to change and the error messages can be swallowed.
I've explained this a lot better at:
http://bobbuzzard.blogspot.co.uk/2012/08/the-importance-of-page-messages.html