You need to sign in to do that
Don't have an account?
venkatasubhashk
Apex repeat not saving values from form
hi
i have follwing code , when saved it is taking the valuse from controller but not from the form
i used Apex repete here
and when i use apex page block table i am able to save the values from Form also..
is there a way to save values through apex repete also...
<apex:page standardController="Opportunity" extensions="TVA_Billing_Itemssubhash" sidebar="false"> <apex:form> <apex:pageMessages /> <apex:pageBlock title="Add Billing Items"> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}" rerender="error" /> </apex:pageBlockButtons> <table border='0'> <tr> <apex:repeat value="{!opps}" var="q"> <tr bgcolor='#E0FFFF'> <th>Opportunity Name</th> <th>Header Opportunity</th> <th>Stage</th> <th>Account</th> <th>Closedate</th> <th>Probability</th> <th>Amount</th> </tr> <td><apex:outputField value=" {!q.name}"/></td> <td> <apex:inputField value=" {!q.Header_Opportunity__c}"/> </td> <td><apex:inputField value=" {!q.stagename}"/> </td> <td> <apex:inputField value=" {!q.Accountid}"/> </td> <td> <apex:inputField value="{!q.CloseDate}"/> </td> <td> <apex:inputField value="{!q.Probability}"/> </td> <td> <apex:inputField value="{!q.amount}"/> </td> <tr bgcolor='#E0FFFF'> <th></th> <th>Product</th> <th>Unit Price</th> <th>Quantity</th> <th></th> <th></th> <th></th> </tr> <apex:repeat value="{!oppli}" var="qa" rows="{!opportunity.Opp_Line_Items_Count__c}"> <tr> <td> </td> <td><apex:outputField value=" {!qa.Product_Code__c}"/></td> <td><apex:inputField value=" {!qa.unitprice}"/></td> <td><apex:inputField value=" {!qa.quantity}"/></td> </tr> </apex:repeat> </apex:repeat> </tr> </table> </apex:pageBlock> </apex:form> </apex:page>
public class TVA_Billing_Itemssubhash { public List<Opportunity> Opps {get; set;} static Integer cnt2; public List<OpportunitylineItem> Oppli {get; set;} public Opportunity [] op; string id; decimal i =0; decimal j = 0; public TVA_Billing_Itemssubhash (ApexPages.StandardController myController) { this.id = ApexPages.currentPage().getParameters().get('id'); //current page Opportunity and Opp Line Items and Price Book Entry ID Opportunity o =[select id,name,date_of_close_date__c ,Final_Closed_Date__c,Week_End_Day__c,Estimated_Start_Date__c,Account.name,Round_off__c,Year_of_close_date__c,Month_Of_Closedate__c,stagename,CloseDate,pricebook2id,amount,probability,Header_Opportunity__c,Accountid,Opp_Line_Items_Count__c,Billing_Contact__c,No_Of_Months_for_Billing__c from Opportunity where id=:id]; OpportunitylineItem[] oli = [select id,Product_Name__c,TotalPrice,ListPrice,PricebookEntry.name,Quantity,PricebookEntry.Product2.Name , PricebookEntry.Product2.id, UnitPrice,PricebookEntryId,Opportunityid,Quote_Original_List_Price__c from OpportunityLineItem where Opportunityid=:o.id] ; Opps = new List<Opportunity>(); Oppli =new List<OpportunitylineItem>(); for(i=0;i<o.No_Of_Months_for_Billing__c;i++) { Opportunity LitOrd = new Opportunity(); LitOrd.stagename = 'Billing-Planned'; LitOrd.probability =100; LitOrd.amount = o.amount; LitOrd.closedate = o.closedate; Opps.add(LitOrd); } for(j=0;j<((o.Opp_Line_Items_Count__c/oli.size())*o.No_Of_Months_for_Billing__c);j++){ for(opportunitylineitem oli1:oli){ OpportunitylineItem LitOrdch = new OpportunitylineItem(); LitOrdch.quantity = oli1.quantity; LitOrdch.unitprice = oli1.unitprice; LitOrdch.opportunityid = o.id; LitOrdch.PricebookEntryId=oli1.PricebookEntryId; LitOrdch.Product_Code__c = oli1.PricebookEntry.name; Oppli.add(LitOrdch); } } } public PageReference save() { try{ insert opps; insert Oppli; } catch (DMLException e) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Oops An Error Occured!')); return null; } return(new ApexPages.StandardController(Opps[0])).view(); } }
I've created a small test case for this in my dev org as follows:
Page:
Controller:
I edit the contacts on the page to change the first name from "Repeat" to "Edited" and the inserted contacts have the correct information in them.
All Answers
Your code looks correct to me. The fact that you have backed the input fields in the repeat with the oppli list elements should mean that the values get applied to the list before the action method to save is invoked.
Are you seeing any errors when you save, or are the values that are stored simply different to those that you enter?
Have you tried adding debug into the save method to output the contents of the array to see whether the entered values are applied at any point?
I see no Errors on save
the values which are stored are Different from i enter
The values its saving from controller when i am taking Apex repete
but whe i use same controller and use apex:pageblock its taking the values from form also !
I've created a small test case for this in my dev org as follows:
Page:
Controller:
I edit the contacts on the page to change the first name from "Repeat" to "Edited" and the inserted contacts have the correct information in them.
i Hope There is a bug in my code i re written the code its working fine now
Thanks.
Glad to hear you got there.
hi
now i used the normal controller to save values
here i am able to save close date but stagename is not chaning when saved
Its taking same value...
when i hit save the changed closedate on visualforce is saved on record but stagename is not changed
i have opportunity lookup on Opportunity..