You need to sign in to do that
Don't have an account?

value not accessible from different vf pages having same controller
i am not able to access the enteredacc variable value in my other vf pages,i am using a single controller and also while moving from one page to another i am setting redirect to false,here is my apex classes and vf pages (3)
apex class:
public class picklistdemo1{
public picklistdemo1(ApexPages.StandardController controller) {
}
public String enteredacc {get; set;}
public String Acno1{get;set;}
public String Acname{get;set;}
public Double AcAnnualRevenue{get;set;}
public String AcPhone{get;set;}
public Date Acdate{get;set;}
public void accDetails()
{
system.debug('enteredaccno is '+enteredacc);
if(enteredacc == '' || enteredacc == null){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter valid Account number or if you are a new user register by clicking the below button'));
return ;
}
else
{
List<Account> acc=[Select Name,AccountNumber,AnnualRevenue,Phone,SLAExpirationDate__c from Account where AccountNumber= :enteredacc];
for(Account a : acc)
{
Acno1=a.AccountNumber;
Acname=a.Name;
AcAnnualRevenue=a.AnnualRevenue;
AcPhone=a.Phone;
Acdate=a.SLAExpirationDate__c;
}
}
}
public PageReference show1() {
return null;
}
public ORDER__c rec=new ORDER__c();
public List<SelectOption> listofbooks{get;set;}
public list<String> selectedbooks { get; set; }
public PageReference add() {
rec.Accountname__c=enteredacc;
rec.select_books__c=String.join(selectedbooks,',');
insert rec;
return null;
}
public PageReference gotoPage() {
PageReference pr = Page.multipicklist;
pr.setRedirect(false);
return pr;
}
public PageReference gotoPageagain() {
PageReference pr = Page.adding_order;
pr.setRedirect(false);
return pr;
}
public picklistdemo1()
{
listofbooks=new List<SelectOption>();
listofbooks.add(new SelectOption('b1','b1'));
listofbooks.add(new SelectOption('b2','b2'));
listofbooks.add(new SelectOption('b3','b3'));
listofbooks.add(new SelectOption('b4','b4'));
listofbooks.add(new SelectOption('b5','b5'));
listofbooks.add(new SelectOption('b6','b6'));
listofbooks.add(new SelectOption('b7','b7'));
listofbooks.add(new SelectOption('b8','b8'));
listofbooks.add(new SelectOption('b9','b9'));
listofbooks.add(new SelectOption('b10','b10'));
}
}
istvf page:
<apex:page standardController="Account" extensions="picklistdemo1">
<apex:form >
<apex:pageBlock id="firstblock" >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:pageBlockSection >
<apex:outputText >Enter Account Number:</apex:outputText>
<apex:inputText value="{!enteredacc}"/>
</apex:pageBlockSection>
<apex:commandButton value="Search" action="{!accDetails}" rerender="firstblock,nextblock,showmsg"/>
<apex:outputText >enteredacc:{!enteredacc}</apex:outputText>
<apex:commandButton value="Next!" action="{!gotoPage}"/>
</apex:pageBlock>
<apex:pageBlock id="nextblock">
<apex:pageBlockSection title="ACCOUNTDETAILS">
<apex:outputText >Account Number:</apex:outputText>
<apex:inputText value="{!Acno1}"/>
<apex:outputText >Account Name:</apex:outputText>
<apex:inputText value="{!Acname}"/>
<apex:outputText >Annual Revenue:</apex:outputText>
<apex:inputText value="{!AcAnnualRevenue}"/>
<apex:outputText >Phone No.:</apex:outputText>
<apex:inputText value="{!AcPhone}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="REGESTRATION">
<apex:inputText value="{!Account.AccountNumber}"/>
<apex:inputText value="{!Account.name}"/>
<apex:inputText value="{!Account.AnnualRevenue}"/>
<apex:inputText value="{!Account.Phone}"/>
<apex:inputText value="{!Account.SLAExpirationDate__c}"/>
<apex:commandButton value="REGISTER!" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
2nd vf:
<apex:page controller="picklistdemo1">
<apex:form >
<apex:outputPanel >
<apex:outputLabel >select book from the list</apex:outputLabel>
<apex:selectList value="{!selectedbooks}" size="6" multiselect="true">
<apex:selectOptions value="{!listofbooks}">
<apex:commandbutton value="Show Values" action="{!show1}" rerender="pbs1,pbs2"/>
<apex:commandButton value="NEXT" action="{!gotoPageagain}"/>
</apex:selectOptions>
</apex:selectList>
</apex:outputPanel>
</apex:form>
<apex:pageBlock title="selected books">
<apex:pageBlockSection id="pbs1">
<apex:pageBlockSectionItem >
{!selectedbooks}
</apex:pageBlockSectionItem>
<apex:pageBlock title="accountvalue">
<apex:pageBlockSection id="pbs2">
<apex:pageBlockSectionItem > {!enteredacc}</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
3rd vf:
<apex:page controller="picklistdemo1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="order information">
<apex:outputText > value="{!enteredacc}"</apex:outputText>
<apex:outputText > value="{!selectedbooks}"</apex:outputText>
<apex:commandButton value="PLACE ORDER" action="{!add}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
please help ,i am stuck in these for several hours.....
Thanks in advance
apex class:
public class picklistdemo1{
public picklistdemo1(ApexPages.StandardController controller) {
}
public String enteredacc {get; set;}
public String Acno1{get;set;}
public String Acname{get;set;}
public Double AcAnnualRevenue{get;set;}
public String AcPhone{get;set;}
public Date Acdate{get;set;}
public void accDetails()
{
system.debug('enteredaccno is '+enteredacc);
if(enteredacc == '' || enteredacc == null){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter valid Account number or if you are a new user register by clicking the below button'));
return ;
}
else
{
List<Account> acc=[Select Name,AccountNumber,AnnualRevenue,Phone,SLAExpirationDate__c from Account where AccountNumber= :enteredacc];
for(Account a : acc)
{
Acno1=a.AccountNumber;
Acname=a.Name;
AcAnnualRevenue=a.AnnualRevenue;
AcPhone=a.Phone;
Acdate=a.SLAExpirationDate__c;
}
}
}
public PageReference show1() {
return null;
}
public ORDER__c rec=new ORDER__c();
public List<SelectOption> listofbooks{get;set;}
public list<String> selectedbooks { get; set; }
public PageReference add() {
rec.Accountname__c=enteredacc;
rec.select_books__c=String.join(selectedbooks,',');
insert rec;
return null;
}
public PageReference gotoPage() {
PageReference pr = Page.multipicklist;
pr.setRedirect(false);
return pr;
}
public PageReference gotoPageagain() {
PageReference pr = Page.adding_order;
pr.setRedirect(false);
return pr;
}
public picklistdemo1()
{
listofbooks=new List<SelectOption>();
listofbooks.add(new SelectOption('b1','b1'));
listofbooks.add(new SelectOption('b2','b2'));
listofbooks.add(new SelectOption('b3','b3'));
listofbooks.add(new SelectOption('b4','b4'));
listofbooks.add(new SelectOption('b5','b5'));
listofbooks.add(new SelectOption('b6','b6'));
listofbooks.add(new SelectOption('b7','b7'));
listofbooks.add(new SelectOption('b8','b8'));
listofbooks.add(new SelectOption('b9','b9'));
listofbooks.add(new SelectOption('b10','b10'));
}
}
istvf page:
<apex:page standardController="Account" extensions="picklistdemo1">
<apex:form >
<apex:pageBlock id="firstblock" >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:pageBlockSection >
<apex:outputText >Enter Account Number:</apex:outputText>
<apex:inputText value="{!enteredacc}"/>
</apex:pageBlockSection>
<apex:commandButton value="Search" action="{!accDetails}" rerender="firstblock,nextblock,showmsg"/>
<apex:outputText >enteredacc:{!enteredacc}</apex:outputText>
<apex:commandButton value="Next!" action="{!gotoPage}"/>
</apex:pageBlock>
<apex:pageBlock id="nextblock">
<apex:pageBlockSection title="ACCOUNTDETAILS">
<apex:outputText >Account Number:</apex:outputText>
<apex:inputText value="{!Acno1}"/>
<apex:outputText >Account Name:</apex:outputText>
<apex:inputText value="{!Acname}"/>
<apex:outputText >Annual Revenue:</apex:outputText>
<apex:inputText value="{!AcAnnualRevenue}"/>
<apex:outputText >Phone No.:</apex:outputText>
<apex:inputText value="{!AcPhone}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="REGESTRATION">
<apex:inputText value="{!Account.AccountNumber}"/>
<apex:inputText value="{!Account.name}"/>
<apex:inputText value="{!Account.AnnualRevenue}"/>
<apex:inputText value="{!Account.Phone}"/>
<apex:inputText value="{!Account.SLAExpirationDate__c}"/>
<apex:commandButton value="REGISTER!" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
2nd vf:
<apex:page controller="picklistdemo1">
<apex:form >
<apex:outputPanel >
<apex:outputLabel >select book from the list</apex:outputLabel>
<apex:selectList value="{!selectedbooks}" size="6" multiselect="true">
<apex:selectOptions value="{!listofbooks}">
<apex:commandbutton value="Show Values" action="{!show1}" rerender="pbs1,pbs2"/>
<apex:commandButton value="NEXT" action="{!gotoPageagain}"/>
</apex:selectOptions>
</apex:selectList>
</apex:outputPanel>
</apex:form>
<apex:pageBlock title="selected books">
<apex:pageBlockSection id="pbs1">
<apex:pageBlockSectionItem >
{!selectedbooks}
</apex:pageBlockSectionItem>
<apex:pageBlock title="accountvalue">
<apex:pageBlockSection id="pbs2">
<apex:pageBlockSectionItem > {!enteredacc}</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
3rd vf:
<apex:page controller="picklistdemo1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="order information">
<apex:outputText > value="{!enteredacc}"</apex:outputText>
<apex:outputText > value="{!selectedbooks}"</apex:outputText>
<apex:commandButton value="PLACE ORDER" action="{!add}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
please help ,i am stuck in these for several hours.....
Thanks in advance
All Answers
Try to pass the value as a parameter like following and see if this solves the issue:
PageReference pr = new PageReference('/apex/adding_order?enteredacc='+enteredacc);
pr.setRedirect(false);
return pr;
Also in the constructor do the following:
public picklistdemo1(ApexPages.StandardController controller) {
if(apexpages.currentpage().getparameters().get('enteredacc') != NULL){
enteredacc = apexpages.currentpage().getparameters().get('enteredacc');
}
}
If this solves the answer, mark this as solved.