+ Start a Discussion
venkatasubhashkvenkatasubhashk 

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();
       
 }
 
 
        
        }

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I've created a small test case for this in my dev org as follows:

 

Page:

 

<apex:page standardController="Account" extensions="RepeatTest">
  <apex:form >
   <apex:pageBlock title="Account Detail">
      <apex:pageBlockSection title="Account">
            <apex:inputField value="{!Account.Name}"/>
            <apex:inputField value="{!Account.Description}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Contacts">
         <apex:repeat value="{!contacts}" var="Contact">
            <apex:inputField value="{!Contact.FirstName}"/>
            <apex:inputField value="{!Contact.LastName}"/>
            <apex:outputField value="{!Contact.AccountId}"/>
         </apex:repeat>
      </apex:pageBlockSection>
  </apex:pageBlock>
   <apex:commandButton value="Save" action="{!save}"/>
  </apex:form>
</apex:page>

 

 

Controller:

 

public class RepeatTest 
{
    private ApexPages.StandardController std;
    
    // the associated contacts
  	public List<Contact> contacts {get; set;}
  	
    public RepeatTest(ApexPages.StandardController stdCtrl)
    {
    	std=stdCtrl;
    	contacts=new List<Contact>();
    	for (Integer idx=0; idx<5; idx++)
    	{
    		contacts.add(new Contact(FirstName='Repeat',
    							     LastName='Test ' + idx,
    		                         AccountId=std.getId()));
    	}
    }

    public PageReference save()
    {
    	// then save the contacts
    	insert contacts;
    	
    	return std.view();
    }
    
}

 

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

bob_buzzardbob_buzzard

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?

venkatasubhashkvenkatasubhashk

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 !

bob_buzzardbob_buzzard

I've created a small test case for this in my dev org as follows:

 

Page:

 

<apex:page standardController="Account" extensions="RepeatTest">
  <apex:form >
   <apex:pageBlock title="Account Detail">
      <apex:pageBlockSection title="Account">
            <apex:inputField value="{!Account.Name}"/>
            <apex:inputField value="{!Account.Description}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Contacts">
         <apex:repeat value="{!contacts}" var="Contact">
            <apex:inputField value="{!Contact.FirstName}"/>
            <apex:inputField value="{!Contact.LastName}"/>
            <apex:outputField value="{!Contact.AccountId}"/>
         </apex:repeat>
      </apex:pageBlockSection>
  </apex:pageBlock>
   <apex:commandButton value="Save" action="{!save}"/>
  </apex:form>
</apex:page>

 

 

Controller:

 

public class RepeatTest 
{
    private ApexPages.StandardController std;
    
    // the associated contacts
  	public List<Contact> contacts {get; set;}
  	
    public RepeatTest(ApexPages.StandardController stdCtrl)
    {
    	std=stdCtrl;
    	contacts=new List<Contact>();
    	for (Integer idx=0; idx<5; idx++)
    	{
    		contacts.add(new Contact(FirstName='Repeat',
    							     LastName='Test ' + idx,
    		                         AccountId=std.getId()));
    	}
    }

    public PageReference save()
    {
    	// then save the contacts
    	insert contacts;
    	
    	return std.view();
    }
    
}

 

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.

This was selected as the best answer
venkatasubhashkvenkatasubhashk

i Hope There is a bug in my code i re written the code its working fine now 

 

Thanks.

bob_buzzardbob_buzzard

Glad to hear you got there.

venkatasubhashkvenkatasubhashk

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...

 

public class Oppctrl
{

  


   


    public PageReference save() {
    
        update opps;
       
     update oppli;
   
  return null;
   
    }
    
public Opportunity Op ;
public Opportunity[] Opps ;
public OpportunitylineItem[] Oppli ;
public OpportunitylineItem[] Oli ;


 
public Oppctrl()
{

this.id =ApexPages.currentPage().getParameters().get('id');
op =[select id,name,Total_Invoiced__c,Total_Planned__c,Total_Submitted__c,ownerid,Purchase_order__c,Account.name,stagename,CloseDate,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];
oli = [select id,Quantity,delete__c ,pricebookentry.name,UnitPrice,Opportunityid,Quote_Original_List_Price__c,Product_Code__c   from OpportunityLineItem where opportunityid=:id];
opps =[select id,ownerid,name,Account.name,stagename,CloseDate,amount,probability,Header_Opportunity__c,Accountid,Opp_Line_Items_Count__c,Billing_Contact__c,No_Of_Months_for_Billing__c from Opportunity where Header_Opportunity__c =:id];

oppli = [select id,Line_Item_Total__c ,Quantity,delete__c ,description,UnitPrice,Opportunityid,Quote_Original_List_Price__c,Product_Code__c   from OpportunityLineItem where opportunityid in: opps];
//oppli = [select id,Quantity,UnitPrice,Opportunityid,Quote_Original_List_Price__c,Product_Code__c   from OpportunityLineItem where opportunityid in:opps or Product_Code__c =: opps[0].name];

}
public String getname()
{
return 'Oppctrl';
}
public Opportunity getop()
{
return op;
}

public Opportunity [] getopps()
{
return opps;
}

public OpportunitylineItem[] getoppli()
{

return oppli;
}
public OpportunitylineItem[] getoli()
{

return oli;
}


}

 

<apex:page controller="Oppctrl" sidebar="false">
 
<apex:form >

<apex:pageMessages />
<apex:pageBlock title="Manage Billings">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>

</apex:pageBlockButtons>



<table border='0' style="empty-cells: hide" align='left' >


<tr bgcolor='#C0C0C0 '>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>

</tr>
<tr>
<td></td>
<td><b> Opportunity Owner </b></td>
<td><apex:outputField value=" {!op.ownerid}"/></td>
<td><b> Total </b></td>
<td>  
   
<apex:outputPanel id="gt">
 <!--<apex:outputText value="val:{!gtotal}"/> -->
<apex:outputText value="{!gtotal}"/>
</apex:outputPanel>

      </td>   
</tr>

<tr>
<td></td>
<td><b>Opportunity Name</b></td>
<!--<td><apex:outputField value="{!op.Name}"/></td> -->
<td><apex:outputLink value="/{!op.id}" target="_blank">{!op.name}</apex:outputLink></td>
<td><b>Planned</b></td>
<!--<td>{!op.Total_Planned__c}</td>-->

<td>
NULL
</td>

</tr>

<tr>
<td></td>
<td><b>Account</b></td>
<td><apex:outputField value="{!op.Accountid}"/></td>
<td><b>Submitted</b></td>
<td>{!op.Total_Submitted__c}</td>
</tr>

<tr>
<td></td>
<td><b>Billing Contact</b></td>
<td><apex:outputField value="{!op.Billing_Contact__c}"/></td>
<td><b>Invoiced</b></td>
<td>{!op.Total_Invoiced__c}</td>
</tr>

<tr>
<td></td>
<td><b>Purchase Order</b></td>
<td><apex:outputField value="{!op.Purchase_order__c}"/></td>
<td><b>Difference</b></td>
<td>Difference</td>
</tr>

<tr>
<td></td>

<td></td>
<td></td>
</tr>
<tr><td></td></tr>
<tr>

<th></th>
<th bgcolor='#C0C0C0 '>Product</th>
<th bgcolor='#C0C0C0 '>Unit Price</th>
<th bgcolor='#C0C0C0 '>Quantity</th>
<th></th>


<th></th>
</tr>
<apex:repeat value="{!oli}" var="l">
<tr>
<td>
</td>
<td><apex:outputField value="{!l.Pricebookentry.name}"/></td>
<td><apex:outputField value="{!l.unitprice}"/></td>
<td><apex:outputField value="{!l.quantity}"/></td>
</tr>
</apex:repeat>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>

<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>Amount</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>

<td><b><apex:outputField value=" {!q.name}"/></b></td>
<!-- <td> <apex:inputField value=" {!q.Header_Opportunity__c}"/> </td> -->
<td> <apex:inputfield value=" {!q.stagename}"/> 
 

</td>

<td> <apex:inputField value="{!q.CloseDate}"/> 

</td> 


<td>action support</td>

<tr bgcolor='#E0FFFF'>

<th></th>
<th>Delete</th>
<th>Product</th>
<th>Unit Price</th>
<th>Quantity</th>
<th>Description</th>

<th></th>
 <th></th> <th></th>
</tr>


<apex:repeat value="{!oppli}" var="qa" >
 <apex:outputPanel rendered="{!IF((qa.Opportunityid == q.id),true,false)}">
 <!-- <apex:repeat value="{!oppli}" var="qa" rendered="{if (oppli.Opportunityid == opps.id),true,false}"> -->
<tr>
<td>
</td>
<td>
<apex:inputField value="{!qa.Delete__c}"/>
</td>

<td><apex:outputField value="{!qa.Product_Code__c}"/></td>
<td><apex:inputField value="{!qa.unitprice}"/></td>




<td><apex:inputField value="{!qa.quantity}">
<apex:actionSupport event="onchange" action="{!grandtotal}" rerender="gt"  status="wait"/>
<apex:actionStatus id="wait" startText=" (pls wait...)"/> 
<apex:actionSupport event="onmousemove" action="{!incrementCounter}" rerender="counter"  status="wait1"/>
<apex:actionStatus id="wait1" startText="(pls wait individual...)"/> 
</apex:inputField>

 </td>
<td>
<apex:outputField value="{!qa.description}"/>
</td>

<td>

<apex:inputCheckBox value="{!qa.Delete__c}" id="primaryCheckBox" disabled="{!NOT(qa.Delete__c)}" onclick="deSelectOthers(this)" />
</td>

<td>
<apex:outputPanel id="counter">
<apex:outputText value="Calc!:{!countindvidual}"/>
</apex:outputPanel>



</td>





</tr>
</apex:outputpanel>
</apex:repeat>




</apex:repeat>

</tr>

</table>
     

</apex:pageBlock> 

</apex:form>
</apex:page>

 when i hit save the changed closedate on visualforce is saved on record but stagename is not changed

 

i have opportunity lookup on Opportunity..