0

I have a table that is populated from values from a custom object. For each record, I have an <apex:inputField> that shows the Quantity value for a record and the user is able to modify the value. There is a <apex:commandButton> that calls an APEX function to update the value. I rerender the field but the value does not update anywhere. Attached is the code for the APEX and the VF.

VF Code:

<apex:form>
<apex:pageBlock >
<apex:pageBlockTable id="VAN_TABLE" value="{!outSku}" var="VAN"  style="table">
<apex:column >
<apex:facet name="header">VAN Type</apex:facet>
<apex:outputText value="{!VAN.VANType__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Item Code</apex:facet>
<apex:outputText value="{!VAN.Item_Code__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Item Description</apex:facet>
<apex:outputText value="{!VAN.ItemDescription__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Quantity Needed</apex:facet>
<apex:inputField id="newQ" value="{!VAN.Quantity__c}"/>
<apex:commandButton action="{!retrieve}" rerender="newQ" value="SUBMIT">
    <apex:param name="singleID" value="{!VAN.Item_Code__c}"/>
    <apex:param name="singleQ" value="{!VAN.Quantity__c}"/>
</apex:commandButton>

</apex:column>
</apex:pageBlockTable>
<apex:commandButton action="{!retrieve}" rerender="VAN_TABLE" value="GET MY LIST!" />

</apex:pageBlock>
</apex:form>
<style>
table {
border-collapse: collapse;
width: 100%;
}

th, td {
text-align: left;
padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}
</style>

The APEX code:

public class ProductByVan{

// The action function parameter gets set here - this is the input
//public String skey {get; set;}

// The output is set here so it can be re-rendered into the page
public List<VAN__c> outSku {get; set;}

public PageReference retrieve() {
   // TODO why is this only returning on and anarbitrary one at that?
   // Pass in the skey via a bind variable
   List<VAN__c> skus = [
           select Item_Code__c, VANType__c, ItemDescription__c, Quantity__c
           from VAN__c
           where VANType__c = 'ALBAIK'
           ];
   // Pass out the value
   outSku = skus;
   return null;
 }
public void setValue() {
  String itemID = Apexpages.currentPage().getParameters().get('singleID');
  Decimal newQ = Decimal.valueOf(Apexpages.currentPage().getParameters().get('singleQ'));
  List<VAN__C> updateQ = [select Quantity__c from VAN__c where Item_Code__c = 'itemID'];
  if (!updateQ.isEmpty()) {
  VAN__c item = updateQ[0];
  item.Quantity__c = newQ;
  update item;
  }
  }

}
0
<apex:commandButton action="{!retrieve}" rerender="newQ" value="SUBMIT">
    <apex:param name="singleID" value="{!VAN.Item_Code__c}"/>
    <apex:param name="singleQ" value="{!VAN.Quantity__c}"/>
</apex:commandButton>

I believe you meant to use setValue on this specific button? like this:

<apex:commandButton action="{!setValue}" rerender="newQ" value="SUBMIT">
        <apex:param name="singleID" value="{!VAN.Item_Code__c}"/>
        <apex:param name="singleQ" value="{!VAN.Quantity__c}"/>
    </apex:commandButton>
1
  • I changed the method (silly mistake) but now I am getting an invalid decimal even after regex and parsing of the string. Invalid decimal: Error is in expression '{!setValue}' in component <apex:commandButton> in page custorder: Class.ProductByVan.setValue: line 24, column 1 – R83nLK82 Jul 5 '18 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.