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
Tina DamTina Dam 

Passing Parameters to a Visualforce page then to a Record Page

Hi,

I may have this more complicated than it should be or there may be an easier way to do this.

I have a custom object (Invoice) that is a child to the Opportunity. We require the reps to look up an Invoice in Salesfore and attach the corresponding Opportunity to the custom lookup field Opportunity__c on the Invoice object

I wanted to make it as easy as possible for them, with as less clicks as possible. So I created a custom list button on the Invoice related list on the Opportunity page that brings them to a Visualforce page where they can search for an Invoice.
User-added image


Custom list button:  https://c.cs8.visual.force.com/apex/InvoiceHeaderSearch       I'd like to add this to the end to pass over the id (?id={!Opportunity.Id})


The visualforce page includes a search function for the Invoice and return results. It also includes an Edit link next to the results

Visualforce page:
My question is: Is it possible to pass the Opportunity ID over to the Visualforce page and then have it pass to the Edit link, so when the reps click on the Edit link, the Opportunity__c field is auto populated with the Opportunity ID?

Here is my visualforce page:
<apex:page standardController="Invoice_Header__c" extensions="Search" >

  <style type = "text/css">
    .Bld { font-weight:bold;}
  </style>
  
  <apex:form >
  
    <apex:pageblock title="Invoice" >
      <table align = "center" width = "100%" cellspacing = "5">
        <tr>
          <td class = "Bld">Invoice Name</td>
          <td><apex:inputText value="{!invName}" /></td>          
        </tr>
        <tr>
          <td align = "center" class = "Bld" colspan = "2"><apex:commandButton value="Search" action="{!find}"/></td> 
        </tr>        
      </table>
       
    </apex:pageblock>
        
    <apex:pageBlock title="Search Result">
      <apex:pageblockTable value="{!invList}" var="a">
        <apex:column >
        <apex:outputLink title="" value="/{!a.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
          <apex:outputlink value="https://cs8.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
        </apex:column>
        <apex:column value="{!a.id}"/>
      </apex:pageBlockTable>     
    </apex:pageBlock>    
      
  </apex:form>
</apex:page>
               
User-added image Controller: public with sharing class invsearchcontroller {      public list <Invoice_Header__c> acc {get;set;}      public string searchstring {get;set;}      public invsearchcontroller(ApexPages.StandardSetController controller) {      }      public void search(){        string searchquery='select name, Invoice_Date__c, Total__c,Territory__c,id from Invoice_Header__c where name like \'%'+searchstring+'%\' Limit 20';        acc= Database.query(searchquery);      }      public void clear(){      acc.clear();      }    } Thanks
KevinPKevinP
Yes, you can. but you have to think ahead abit. 

You can override that edit button to point to a visualforce page. So long as that visualforce page relies on or extends the standard controller for opportunity, the opportunity ID will be available for you in apex. 
nitin sharmanitin sharma
I think you can use standardcontroller class methods such as getid() or getrecord().From Getrecord() method ,you can extract opportunity Id currently in context.