function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raviteja Epuri 1Raviteja Epuri 1 

Clone row of Pageblock table and rerender - Visualforce,Apex

Hi Experts!!

Clone functionality is not working as expected :(

Expected requirement is after click of clone i want new row to be added at the last and Sequesnce number is in order.
pageblock table on page load

Issue is once we click on clone its changing the sequence number(along with other data in the row) of source row.
 
Page block table on click of clone

Code :
<!-- Action funtion to clone entry -->
        <apex:actionFunction action="{!cloneEntry}" name="cloneEntry1" reRender="pgMsgs,lstproducts" status="pageStatus">
            <apex:param name="entryToClone" value=""/>
        </apex:actionFunction>
<apex:pageBlockTable value="{!lstEntries}"  var="oli" width="80%" id="pbTable" rendered="{!lstEntries.size >0}">          
                <apex:column >
                  <u><a style="cursor: pointer;" onclick="cloneEntry1('{!oli.APT_Sequence_Number__c}');"> <b>Clone</b> </a></u>                 
                </apex:column>
                <apex:column headerValue="Sequence Number">   
                 <b><apex:outputField value="{!oli.APT_Sequence_Number__c}" />  </b>
                </apex:column>
                <!--apex:column value="{!oli.APT_Product__c}" headerValue="Product" /--> 
                <apex:column headerValue="Classification">                
                <apex:inputField value="{!oli.APT_Classification__c}" id="classID" />
                </apex:column>
</apex:pageBlockTable>

public void cloneEntry(){
    
          Integer entryToClone= integer.valueof(Apexpages.currentPage().getParameters().get('entryToClone'));                      
          APT_Opportunity_Product_Line_Item__c opToClone= new APT_Opportunity_Product_Line_Item__c();         
           opToClone= lstEntries[entryToClone];                    
           opToClone.APT_Sequence_Number__c= lstEntries.size();
          lstEntries.add(opToClone);      
         
    }



I have tried multiple scenarios on the method no success.

Please suggest me whats going wrong here.

Thanks in advance.
Panduranga GollaPanduranga Golla
use wrapper class for clone functionality,you can acheive this task