function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
goosegoose 

passing custom object via URL parameter

Hi,

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:

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

and the controller get:

Code:
   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.

Thanks
 

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
iceberg4uiceberg4u
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.

Code:
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;
        break;
      }
    }
    // When id isn't specified
    if (flight == null)
    {
      flight = new Flight__c();
    }
  }
  return flight;
}


 

goosegoose

Thanks - that will work perfectly.

 

Much appreciated

Gitakul0121Gitakul0121

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.

 

https://na7.salesforce.com/a06/e?00NA0000002ld3f={!Opportunity.Id}&00NA0000002lcvS={!Opportunity.Name}&00NA0000002ld4d={!Opportunity.Projected_Go_Live_Date__c}&00NA0000002leO0={!Opportunity.Amount}&CF00NA0000002VTPv_lkid={!Opportunity.AccountId}

 

Appreciate you help,

Gita

VeevaEmsVeevaEms

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

NK123NK123

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.

 

~NK