You need to sign in to do that
Don't have an account?
Passing not saved paramenter from visualforce to apex
Hi,
I know there are plenty of explanations on how to pass a parameter from Salesforce to Apex, but they dont solve my question.
I have a button on account, Request Extension, that takes the user to a visualforcepage asking him the reason of the extension. I need to take the answer of the user and pass it over to another visualforce page. I want to pass the paramenter through the URL.
This is my solution that so far I didnt make it work....
Visualforce page
<apex:page standardController="Account" showHeader="true" showChat="true" tabStyle="Account" extensions="AccountExtension"> <apex:sectionHeader title="Main Account Extension" subtitle="{!Account.Name}"/> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Next" action="{!EditExtensionData}"> <apex:param name="Reason" value="{!Account.Atlas_Code_Usage__c}"/> </apex:commandButton> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:PageBlockButtons> <div style="position:absolute; top:120px; left:380px;"> <apex:outputLabel value="Extension Reason"/> <apex:inputField value="{!Account.Atlas_Code_Usage__c}""/> </div> </apex:pageBlock> </apex:form> </apex:page>
The field Atlas_Code_Usage will belong to the new Extension account I want to create, not to the one the user starts the wizard from.
This is the controller code:
public with sharing class AccountExtension { private Account acc1; private Account acc2; public AccountExtension(ApexPages.StandardController stdController) { this.acc1 = (Account)stdController.getRecord(); this.acc2= [Select Id,Atlas_Code_Usage__c From Account Where (Id=:acc1.Id)]; } public PageReference EditExtensionData() { String ExtensionReason = System.currentPageReference().getParameters().get('Reason'); PageReference pageRef= new PageReference('/apex/ExtensionData?id='+acc1.Id+'&Reason='+ExtensionReason); pageRef.setredirect(true); return pageRef; } }
What I get as result is the following:
https://c.cs7.visual.force.com/apex/ExtensionData?id=001M000000Jbe7tIAB&Reason=null
Never get a value in the parameter I want to pass over.
Really appreciate your help.
Regards,
Antonio
The field is bound to the standard controller record, which is acc1, not to your internally created record, which is acc2. So you need to reference acc1.Atlas_Code_Usage__c.
(It isn't clear to me why you need both acc1 and acc2 in your controller.... but that is another issue...)
All Answers
Hi,
Thanks for your fast reply.
I modified the code as you said but still getting null.
Eventually what I want is to create a process to guide de user. The first question is the reason of the extension, and depending on this, he must fulfill different information.
Consider that the field Atlas_Code_Usage is a value that will belong to the new account, in the account we start the process from doesnt have any value, is null, and I think thats the reason why I get a null... Do I need to save this value in some new variable or something for it to work?
Thanks a lot
Looks like you are binding the input field to Account.Atlas_Code_Usage__c, so your extension can get the vlaue from there.
Remove the param fro mthe command button. Then, in the extension
PageReference pageRef= new PageReference('/apex/ExtensionData?id='+acc1.Id+
'&Reason='+acc1.AtlasCodeUsage__c);
Hi,
I cant do that because the value acc1.Atlas_Code_usage__c is null. I ask for this value in order to create a new account and this will be a field of the new account, not of the one I start with.....
Is there a solution for this?
Thanks a lot
Acc1 is the standard controller record. So it should not be null when the action is executed since it is set from the inputField you have bound to it.
(or maybe it is null if the user hasn't entered a reason, which you should test for).
Hi,
I changed to code as you said and still not getting the right value. This is the code after the changes:
VF:
Controller:
The Atlas_Code_Usage field is a picklist, in case it might help.....
Thanks for your help...I have been fow a whole day trying to figure out how to get this parameter to go from one page to the other....Really appreciate your help.
The field is bound to the standard controller record, which is acc1, not to your internally created record, which is acc2. So you need to reference acc1.Atlas_Code_Usage__c.
(It isn't clear to me why you need both acc1 and acc2 in your controller.... but that is another issue...)
Thnak you very much aballard!!
This is my final code in case it might help someone:
VF:
Apex Controller:
Regards