+ Start a Discussion
@GM@GM 

Please suggest

In apex controller class , how to take the value (in red color) of vf field which is edited.

 

vf code:

<apex:page controller="ProductSearchController" sidebar="false" showHeader="false">

<apex:stylesheet value="{!URLFOR($Resource.styles, 'styles.css')}"/>
    <apex:form >
        <apex:pageBlock >
 
            <apex:pageBlockButtons >
                <apex:commandButton action="{!back}" value="Back"/>
                <apex:commandButton action="{!order}" value="Place a order"/>
                
            </apex:pageBlockButtons>
            <apex:pageMessages />
 
            <apex:pageBlockSection title="You Selected following items" columns="1" collapsible="false">
                <apex:pageBlockTable value="{!selectedCategories}" var="c" title="Double click on Quantity to edit it">
                    <apex:column value="{!c.cat.Name__c}" headerValue="Name"/>
                    <apex:column value="{!c.cat.Price__c}" headerValue="Total Amount"/>
                    <apex:column value="{!c.cat.code__c}" headerValue="Code"/>
                    <apex:column value="{!c.cat.category__c}" headerValue="Category"/>
                    <apex:column headerValue="Quantity">
                    <apex:outputField value="{!c.cat.Quantity__c}">
                    <apex:inlineEditSupport event="ondblclick" showOnEdit="update"/>
                    </apex:outputField>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>  
           
         <br/>
<apex:commandButton id="update" action="{!saveOrder}" value="Save Order" styleclass="updateButton"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Best Answer chosen by Admin (Salesforce Developers) 
ericmonteericmonte

So if your controller has a get set method for the Opportunity you can able to create a new record based off the information that is stored in the VF page.

 

For example:

 

Opportunity opp {get;set;}

 

 

Public pageRefer Save(){

 

CustomObject__c cus = new CustomObject__c(

cus.Name = opp.Name,

cus.Quantity__c = opp.Quantity

....

);

 

Return null;

 

}

 

 

So you want something like that. Let me know if you want something specific.

All Answers

ericmonteericmonte

I'm not sure i'm getting it but is your Visualforce page being used for detail and edit page, and you would only like to use the portion in red in the detail page and not edit?

ericmonteericmonte

Based on my assumption, you can create an extension and create a variable that identifies the page as an edit page. Here is my an exmple code i create in the past to identify what to show on the page during new vs edit a page

/*public with sharing class extFatherhood {
  private final Fatherhood_Program__c father;
  public Contact part {get;set;}
  public Boolean IsView {get;set;}

    public extFatherhood(ApexPages.StandardController controller) {
      this.father = (Fatherhood_Program__c)controller.getRecord();
      
      initPart();
      
      //Determines if this is a new/edit or view
      
      if (IsView ==null &&this.father.Id !=null){
        IsView = true;
        //see if this came from an edit request
        if (apexpages.currentPage().getParameters().get('returl') != null){
          IsView = false;
        }
      }else {
        IsView = false;
      }
    }
    

 and here is a sample code of my VF Page

<!-- this will show the field if it's edit -->
<apex:outputField value = "{!Fatherhood_program__c.Participant__c}" rendered ="{!Not(ISVIEW)}"/>

<!-- this will show the field if it's not edit -->
<apex:inputField value = "{!Fatherhood_Program__c.Name}" rendered ="{!IsVIEW}/>

 let me know if this helps

@GM@GM

Actually whatever values are displaying in that vf page are from the custom object(Product) but In that vf page quantity field is editable field so now i nees to save all those fields in another custom object(order).but how to access that edited quantity field from controller class.

ericmonteericmonte

So if your controller has a get set method for the Opportunity you can able to create a new record based off the information that is stored in the VF page.

 

For example:

 

Opportunity opp {get;set;}

 

 

Public pageRefer Save(){

 

CustomObject__c cus = new CustomObject__c(

cus.Name = opp.Name,

cus.Quantity__c = opp.Quantity

....

);

 

Return null;

 

}

 

 

So you want something like that. Let me know if you want something specific.

This was selected as the best answer