1

My problem is when ever I save a value for the second time it is taking the first value also....When I put system debug I observed that it is entering only into the else part....it is not entering into the if part although the condition is true....dont know why please check

Here is my code

     <apex:pageblocksection title="Early Payment Discount" columns="1">  

      <apex:outputpanel id="RefreshPage">
       <apex:variable value="0" var="rowNum"/>       
         <apex:repeat value="{!Earlypaymentvalues}" var="item">
         <apex:inputHidden value="{!item.RecordId}"/>
           <apex:outputlabel value="Early Payment Discount" style="margin-right:20px;"></apex:outputlabel>        

                  <b> $ </b> <apex:inputtext value="{!item.Amount}" size="7"/> + <b> % </b> <apex:inputtext value="{!item.Discount}" size="7" style="margin-right:20px;"/>  <apex:inputText value="{!item.days}" size="5" /> <apex:outputLabel value="Days Before due date"/>                        

               <apex:commandButton value="Delete" action="{!delcont}" styleClass="Delete" reRender="RefreshPage" status="statusIdForDelete" style="margin-left:30px;" >
                  <apex:param name="contIdParam" value="{!rowNum}" assignTo="{!DeleteId}"/>
                    <apex:param name="contIdParam1" value="{!item.RecordId}" assignTo="{!DeleteFromObjectId}"/>
               </apex:commandButton>
               <apex:actionStatus id="statusIdForDelete" startText="Deleting...">
                 <apex:facet name="stop"></apex:facet>
               </apex:actionStatus>
               <apex:variable value="{!Value(rowNum)+1}" var="rowNum"/>

              <br/>
           </apex:repeat>
           <br/>
          <input type="Hidden" value="{!rowNum}" class="rowvalues" name="rowvalues"/>
             <apex:commandbutton value="Add" action="{!addfield}" rerender="RefreshPage" status="nextrowstatus" />       
                <apex:actionstatus id="nextrowstatus" Starttext="Please Wait....">
                    <apex:facet name="Stop"></apex:facet>
                </apex:actionstatus>
              <apex:commandButton action="{!Saveearly}" reRender="RefreshPage" value="Save"/> 
            </apex:outputpanel>    
     </apex:pageblocksection>  

My Class is

public class InvoicePage {
Private List<Payment_Values>  EarlyPaymentValues; 
public string Invoiceid{get;set;} 
Public string DeleteId{get;set;}
Public string DeleteFromObjectId{get;set;}
public List<Payment_Policy__c> FieldsList {get; set;}
 Set<string> DeleteRecordList=new set<string>();   
    Set<string> DeleteRecordListPayment=new set<string>();

Public invoicepage(){
 FieldsList=[select Id,Early_Amount__c,Early_Days__c, Early_Discount__c, Early_Payment__c from Payment_Policy__c  LIMIT 10];
  if(!FieldsList.isempty()) 
     {
         EarlyPaymentValues = new List<Payment_Values>();
         for(Payment_Policy__c temp : FieldsList)
         {
                                  Payment_Values  AddRec=new Payment_Values();                                  
                                  AddRec.RecordId =temp.Id;
                         //         AddRec.earlypay = temp.Early_Payment__c;
                                  AddRec.Amount=temp.Early_Amount__c;
                                  AddRec.Discount=temp.Early_Discount__c;
                                  AddRec.days=temp.Early_days__c;
                                  EarlyPaymentValues.add(AddRec);
                                    system.debug('EarlyValuessssssss'+AddRec); 
         }

     }
}

Public void setEarlyPaymentValues(List<Payment_Values> S){this.EarlyPaymentValues = S; }

Public List<Payment_Values> getEarlyPaymentValues(){
     if(EarlyPaymentValues ==null){
            EarlyPaymentValues = new List<Payment_Values>();
            EarlyPaymentValues.add(new Payment_Values());
          }
        return EarlyPaymentValues;
}
 public void delCont() {
        integer DelIndex=integer.valueof(DeleteId);
            EarlyPaymentValues.remove(DelIndex);
            if(DelIndex < FieldsList.size()){FieldsList.remove(DelIndex);}
            system.debug('FieldsListFieldsList'+FieldsList);
            if(DeleteFromObjectId!=''){DeleteRecordList.add(DeleteFromObjectId);}
    }
public void addfield()
{ 
  EarlyPaymentValues.add(new Payment_Values());
}
 public Pagereference Saveearly(){

        List<Payment_Policy__c> paymentearly = new list<Payment_Policy__c>();
         for(Payment_Values temp : EarlyPaymentValues){

           if(temp.RecordId == ''){
              Payment_Policy__c early = new Payment_Policy__c();

               early.Early_Amount__c= temp.Amount;
               early.Early_Discount__c = temp.Discount;
               early.Early_Days__c = temp.Days;

              paymentearly.add(early);
              system.debug('Paymenttt'+early);

           }
         }
              If(paymentearly.size()>0){
                        insert paymentearly;
                       system.debug('Paymentt'+paymentearly);
                    }
                    system.debug('fielslist'+fieldslist);
                 if(!FieldsList.IsEmpty())
                    {
                      integer i=0;

                      for(Payment_Policy__c temp : FieldsList){
                       if(temp.Id==EarlyPaymentValues[i].RecordId){
                           temp.Early_Amount__c = EarlyPaymentValues[i].Amount;
                           temp.Early_Discount__c =  EarlyPaymentValues[i].Discount;
                           temp.Early_Days__c =  EarlyPaymentValues[i].Days;
                           system.debug('temptt'+temp);
                        }                                 
                          i=i+1;

                      }
                      List<Payment_Policy__c> temp=[select Id from Payment_Policy__c where Id IN :DeleteRecordList];

                        if(!temp.IsEmpty()){delete temp;}   
                          if(!FieldsList.isEmpty() && temp.isEmpty()){  

                        update FieldsList;
                          system.debug('temppp'+temp +'fielslist'+fieldslist);

                        }
                    }
                    else{
                       FieldsList= new List<Payment_Policy__c>();
                        List<Payment_Policy__c> temp=[select Id from Payment_Policy__c where Id IN :DeleteRecordList];

                        if(!temp.IsEmpty()){delete temp;}   

                       system.debug('tempp'+temp);
                    } 
                 return null;

    }     
}
1
  • 1
    Are you depending on if(!temp.IsEmpty()){delete temp;} to empty temp for you ? You will need to explicitly specify temp= new List<Payment_Policy__c>{}; to make it empty. Commented Oct 29, 2012 at 11:48

1 Answer 1

1

This trick worked out for me...Just placed integer value inside the for loop

 for(Payment_Policy__c temp : FieldsList){
                        integer i=0;
                       if(temp.Id==EarlyPaymentValues[i].RecordId){
                           temp.Early_Amount__c = EarlyPaymentValues[i].Amount;
                           temp.Early_Discount__c =  EarlyPaymentValues[i].Discount;
                           temp.Early_Days__c =  EarlyPaymentValues[i].Days;
                           system.debug('temptt'+temp);
                            i=i+1;
                          system.debug('iiii'+i);
                        }                                 

                      }
1
  • Yeah, it helps to have the counter variable inside the for loop :) Commented Oct 29, 2012 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .