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
BridgetreeBridgetree 

Pass filed value in Command Button

Hi all...

 

 Small Requirement. Pls get me thru.

 

I have franchisee name lookup field (Account) in a Franchisee custom object. I will be adding few products to each of the franchisee in this page.

 

Current req is in my lead visualforce page. I have  a franchisee field (lookup coming from account) here also.

When i enter the data, i will be clicking a button Find Products.

Soon a data list has to be filled with product and its details based on the data in the lookup field above.

It means i need to pass this lookup field value as param value in  button.

 

Pls suggest any help.

 

Thanks in advance

bob_buzzardbob_buzzard

If your visualforce page is backed by the custom object that you set the lookup field into, you don't need to pass any information back to the controller, as it will be automatically sent back via the postback request when the button is clicked.

 

E.g.  Page

 

 

<apex:page standardController="MyObj__c" extensions="ProdExt">
   <apex:form>
      <apex:inputField value="{!MyObj__c.Account__c}"/>
      <apex:commandButton value="Find Products" action="{!findProducts}"/>
      <apex:repeat value="{!products}" var="product">
         <!-- do something with products here -->
      </apex:repeat>
   </apex:form>
</apex:page>

 

 

Controller:

 

 

public class ProdExt
{
   ApexPages.StandardController stdCtrl;
   public List<MyProd__c> products {get; set;}

   public ProdExt(ApexPages.StandardController std)
   {
      stdCtrl=std;
   }

   public PageReference findProducts()
   {
      MyObj__c rec=(MyObj__c) stdCtrl.getRecord();
      products=[select id, Name from MyProd__c where Account__c=:rec.Account__c];

      return null;
   }
}