+ Start a Discussion
sp13sp13 

problem in saving records

i am able to save mutiple records at once but all the records are the same even if i selected/typed different values in each row. it is only saving the values from last row but the dates on the Leave_Date__c are working fine.

 

for example this is what i typed:

 

                Id                               Date           Remarks          Days Off

a3He00000000ktX            09-05-13              A                    Whole

a3He00000000ktX            09-06-13              B                    Half

a3He00000000ktX            09-07-13              C                    Quarter

 

 

these are the records saved:

                Id                               Date           Remarks          Days Off

a3He00000000ktX            09-05-13              C                    Quarter

a3He00000000ktX            09-06-13              C                    Quarter

a3He00000000ktX            09-07-13              C                    Quarter

 

 

 

codes:

<apex:pageBlockSection title="Details" columns="2" rendered="{!showDetails}">
  <apex:pageBlockTable value="{!listOfDates}" var="date" width="500px">
       <apex:column headerValue="LeaveDate"  style="padding: 0px 30px 0px 30px;">
             <apex:outputText value="{0,date,EEE  MM/dd/yyyy}">
                            <apex:param value="{!date}" />
                    </apex:outputText>
                </apex:column>
                <apex:column headerValue="With Pay">
                    <apex:inputField value="{!newleavedetail.WIth_Pay__c}"/>
                </apex:column>
                <apex:column headerValue="Leave Application Id">
                    <apex:outputText value="{!leave.id}"/>
                </apex:column>
                <apex:column headerValue="Day/s Off">
                    <apex:inputField value="{!newleavedetail.Day_s_Off__c}"/>
                </apex:column>
                <apex:column headerValue="Project">
                    <apex:inputField value="{!newleavedetail.Project__c}"/>
                </apex:column>
                <apex:column headerValue="Remarks">
                    <apex:inputField value="{!newleavedetail.Remarks__c}"/>
                </apex:column>
            </apex:pageBlockTable><br/><br/>
            <br />
           </apex:pageBlockSection> 

 

public List<Date> listOfDates{get;set;}

public lad__c newleavedetail {get; set;}
public la__c leave {
      get {
        if (leave == null)
          leave = new la__c();
        return leave;
      }
      set;
    }

public LeaveCC(ApexPages.StandardController controller) {
    listOfDates = new List<Date>();      
    newleavedetail = new lad__c();        //used for saving details
    }



public PageReference savedetail() {
        try {
            for(integer x=0;x < listOfDates.size();x++){
                Datetime d = listOfDates.get(x);
                lad__c leavedetail = new lad__c();
                leavedetail.Leave_Application__c = leave.Id;
                leavedetail.Day_s_Off__c = newleavedetail.Day_s_Off__c;
                leavedetail.WIth_Pay__c = newleavedetail.WIth_Pay__c;
                leavedetail.Project__c = newleavedetail.Project__c;
                leavedetail.remarks__c = newleavedetail.remarks__c;
                
                integer year = integer.valueof(d.format('yyyy'));
                integer month = integer.valueof(d.format('MM'));
                integer day = integer.valueof(d.format('dd'));
                leavedetail.Leave_date__c = date.newinstance(year, month, day); //listOfDates.get(x);
                leaveAppDetailList.add(leavedetail);
            }
            insert leaveAppDetailList;
            
        } catch(Exception e) {
            apexPages.addMessages(e);
        }
        PageReference leaveapppage = new PageReference('/'+leave.id);  
        leaveapppage.setRedirect(true);
        return leaveapppage;
    }

 

 

help!

Best Answer chosen by Admin (Salesforce Developers) 
Sandeep001Sandeep001

You need to use wrapper class and return the list of wrapper class to display and save the information you are displaying in the table in VF page.