+ Start a Discussion

passing custom object via URL parameter


I've written a wizard for updating a custom object.

What I cannot see to do is call the wizard with a parameter that - when passed - will set the an object variable within the wizard.

For example. i have a custom object; Flight__c. On a particular flight's detail page, I want to add a button that will call a custom visualforce page with that flight's id passed as a parameter. eg: na6.salesforce.com/apex/testpage?id=00000SA1Q

In that page - testpage - there is a form that will allow some of that record's values to be edited:

<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:pageBlockSection title="Test set Flight">
            <apex:outputField id="flight" value="{!flight.name}"/>
        <apex:pageBlockSection title="Test pick account">
            <apex:inputField id="account" value="{!flight.Flight_Account__c}" required="true"/>
        <apex:pageBlockSection title="Test pick dep airport">
            <apex:inputField id="dep_airport" value="{!flight.Flight_departure_airport__c}" required="true"/>
        <apex:pageBlockSection title="Test pick arr airport">
            <apex:inputField id="arr_airport" value="{!flight.Flight_arrivals_airport__c}" required="true"/>

and the controller get:

   public Flight__c getFlight() {   
      if(flight == null) flight = new Flight__c();
      return flight;

and the rest of the methods are for various 'prev', 'next' and 'save' buttons - together with getters and setters for other objects. I just can't see where the flight can be initially set from the id paramater.

I'm probably missing something obvious - so a pointer would be really appreciated.


Ron HessRon Hess

Your controller can look at the query string parameter ( in it's constructor) and set a property that your page can access within the wizard.

your page could use < apex : param  to set values when the buttons are pressed, this is common in a wizard
Why dont you write in your next page SystEM.CurrentPage Reference and have id as the parameter easier but security wise its an issue so u cud go for param otherwise.

Mark YoungMark Young

Try adding this to your controller:

Basically, retrieve id from the query parameters and then select it along with the appropriate fields using SOQL.

private string flightId;

/** Constructor of controller */
public bookingWizController()
    flightId = ApexPages.currentPage.getParameters().get('id');  

/** Gets the flight, selecting the existing one from the db if appropriate or else constructing a new one. */
public Flight__c getFlight() {
  if (flight == null) {
    // If id is specified
    if (flightId != null && flightId != '')
      for (Flight__c f : [select Name, Flight_Account__c from Flight__c where Id =: flightId])
        flight = f;
    // When id isn't specified
    if (flight == null)
      flight = new Flight__c();
  return flight;



Thanks - that will work perfectly.


Much appreciated


Hi, this is probably ridumentary by now, but I have created a custom object and am passing field values from the standard opportunity to the custom object. There is a button on the opportunity page to create the new object. I am able to populate the new fields, but they all must be text-based. Is there a way to pass a lookup field value to a field on a new object via URL but have it preserve the lookup functionality in pass. Here is my URL for the new button below. The LAST field after the ampersand is the Opportunity Account. I want that to preserve as a lookup value in the new record.




Appreciate you help,



Gita - did you get a response/answer to this question?


Hi Gita or anyone,


Do we have an answer for Gita's question?
Question is regarding passing the lookup value as parameter to the custom object.
For example: Like passing Opportunity and Account into the custom object page where these will be showned as lookup fields. Currently these lookup parameters are lost and not set properly in the custom object screen.