• Andrew8230
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Is it possible to store a List of custom objects  ( List<CustomObject> ) somewhere and access it later on different pages? The custom object only holds strings and integers.
Sorry if this question seems remedial, but I can't seem to find the answer anywhere...

I have a set of VisualForce pages that make calls to a 3rd party web service that I wrote. This web service requires a "key" that is retrieved by calling the "Login()" function on the web service. This function sends back a string that should be used with all subsequent calls to this web service. My question is, is there some equivalent of session variables I can use in Apex to store this variable? I would like some variable I can set that will live as long as the SF user is logged in, and should only be accessible by that SF user.

Thanks,
Spector


Message Edited by Spector on 10-03-2008 04:12 PM
Hi,

I have a problem with som code I'm developing. I'm not sure if it's down to my apex code, visualforce code or something else - so thought it best to post it here. Sorry if it's the wrong place.

I'm writing a visualforce wizard - based on the standard sample wizard in the documentation: http://wiki.apexdevnet.com/index.php/NewOpportunityController.apex

Most of it seems to be working though the problem is when selecting a number of contacts via a "apex:selectCheckboxes". On this wizard page, both the prev and next buttons return to the current page and not the pages appropriate.

Rather than post the whole code, here's samples;

The button controller code is:


Code:
   public PageReference step0() {
      return Page.bookingwiz0;
   }

   public PageReference step1() {
      return Page.bookingwiz1;
   }

   public PageReference step2() {
      return Page.bookingwiz2;
   }

 
Page bookingwiz0 has the vf code:


Code:
<apex:page controller="bookingWizController">
  <apex:sectionHeader title="Confirm Flight Booking" subtitle="Step 0 of 7"/>
    <apex:form >
      <apex:pageBlock title="Define Flight Name" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!step1}" value="Next"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Set Flight">
            <apex:inputField id="flight" value="{!flight.name}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Test pick account">
            <apex:inputField id="account" value="{!flight.Flight_Account__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 
- which works fine. The 'getters' (I believe is the term) in the controller are:

Code:
   Account account;
Flight__c flight;

public Account getAccount() {
if(account == null) account = new Account();
return account;
} public Flight__c getFlight() { if(flight == null) flight = new Flight__c(); return flight; }

 

Now, the problem is with the next page. This picks a list of passengers from the account's contacts. (They will later be assigned to the flight as m:m objects but for now, they are just stored in the controller as an array of contacts).

Code:
<apex:page controller="bookingWizController">
  <apex:sectionHeader title="Confirm Flight Booking" subtitle="Step 1 of 7"/>
    <apex:form >
      <apex:pageBlock title="Add Passengers" mode="edit">
        <apex:pageBlockButtons >
        
            <apex:commandButton action="{!step0}" value="Previous"/>
            <apex:commandButton action="{!step2}" value="Next"/>
        </apex:pageBlockButtons>
            <apex:pageBlockSection title="Available Passengers" columns="1">
                <apex:selectCheckboxes value="{!passengers}" layout="pageDirection">
                    <apex:selectOptions value="{!passengeritem}"/>
                </apex:selectCheckboxes>
            </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 Now, I did a similar getter and got a read only error message. So I searched for the problem and the solution seemed to be to create a setter too:

Code:
   Contact[] passengers;

   public Contact[] getPassengers() {
       return passengers;
   }
   
   public void setPassengers(Contact[] passengers) {
        this.passengers = passengers;
   }




public List<SelectOption> passengeritemList;

public List<SelectOption> getPassengeritem() {
if (passengeritemList== null) {
List<Contact> contcs= [select id,firstname,lastname from Contact where Contact.Account.id = :flight.Flight_account__c];

passengeritemList= new List<SelectOption>();
for (Contact c : contcs) {
passengeritemList.add(new SelectOption(c.id, c.lastname + ' ' +c.firstname));
}
}
return passengeritemList;
}

 

It behaves as expected on page '0' - but on going to page '1' - either selecting or not selecting contacts from the list - neither the previous or next buttons go to the previous or next pages. The screen is rerendered - so it looks like the buttons are working - but it re-appears on page '1'.

Any ideas folks?

Thanks



  • September 20, 2008
  • Like
  • 0