You need to sign in to do that
Don't have an account?
Nikhil M Kumar
How do I get the value entered in the InputField into the Apex class and also to be inserted into the database? Below is the code I'm trying but doesn't work!
<apex:page showHeader="false" sidebar="false" standardController="Hotel_Menu_Item__c" extensions="MenuTMS" recordSetVar="htlMenu"> <apex:form > <apex:pageBlock title="Menu Items"> <apex:outputText >Hello!</apex:outputText> <br/><br/> <apex:pageBlockTable value="{! htlMenu }" var="htl" cellspacing="10px" cellpadding="10px"> <apex:column value="{! htl.Name }" /> <apex:column value="{! htl.Price__c }" /> <apex:column > <apex:inputText style="width: 50px" value="{!htl.Quantity__c}" /> </apex:column> </apex:pageBlockTable> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page> public class MenuTMS { public List <Hotel_Menu_Item__c> ItemDetails { get; set;} public ApexPages.StandardSetController stdSetController {get; set;} public ApexPages.StandardController stdController {get; set;} public static PageReference save(){ List <Hotel_Menu_Item__c> ItemDetails = [SELECT Id,Name,Price__c,Quantity__c FROM Hotel_Menu_Item__c WHERE Quantity__c != NULL]; List <Double> Amount = new List <Double> (); for(Integer i = 0; i < ItemDetails.size(); i++){ Amount.add((ItemDetails[i].Price__c) * (ItemDetails[i].Quantity__c)); } UPDATE ItemDetails; List <Invoice__c> invoice = new List <Invoice__c>(); for(Invoice__c inv: invoice){ for(Integer j = 0; j < ItemDetails.size(); j++){ inv.Name__c = ItemDetails[j].Name; inv.Price__c = ItemDetails[j].Price__c; inv.Quantity__c = ItemDetails[j].Quantity__c; inv.Amount__c = Amount[j]; } } INSERT invoice; /* for(Integer j = 0; j < ItemDetails.size(); j++){ Invoice__c inv = new Invoice__c(); inv.Name = Hotel_Menu_Item__c.Name; } */ PageReference pageRef = new PageReference('/apex/TMSMenuBillPage'); pageRef.setRedirect(true); return pageRef; } /* public static PageReference gotoMenu(){ PageReference pageRef = new PageReference('apex/TMSMenu'); pageRef.setRedirect(true); return pageRef; } */ public MenuTMS(){ ItemDetails = [SELECT Id,Name,Price__c,Quantity__c FROM Hotel_Menu_Item__c WHERE Quantity__c != NULL]; List <Double> Amount = new List <Double> (); for(Integer i = 0; i < ItemDetails.size(); ++i){ Amount.add((ItemDetails[i].Price__c) * (ItemDetails[i].Quantity__c)); } System.debug(ItemDetails); } /* public static void clearList(){ //Code to clear the Name and price fields. } */ public MenuTMS(ApexPages.StandardSetController controller){ stdSetController = controller; } public MenuTMS(ApexPages.StandardController controller){ stdController = controller; } }