Find your content:

Search form

You are here

Entering into else part only

 
Share

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;

    }     
}

Attribution to: eagerinsf

Possible Suggestion/Solution #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);
                        }                                 

                      }

Attribution to: Eagerin Sf
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3808

My Block Status

My Block Content