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
Aaron Persich 8Aaron Persich 8 

How to update a visualforce page to add the clone function

Hello,

We have the below Visualforce Markup which mass eidts the Asset records when the users select the checkboxes next to the assets.  This works perfectly but I would like to take it a step further to clone and mass edit.  How can I incorporate the clone function into this mass edit function?

<apex:page standardController="Asset" recordSetVar="unused" tabStyle="Asset"
sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. 
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="a" id="table">
<apex:column headerValue="Assert Name">
<apex:inputField value="{!a.name}"/>
</apex:column>
<apex:column headerValue="Account Name">
<apex:inputField value="{!a.AccountID}"/>
</apex:column>
<apex:column headerValue="Product">
<apex:inputField value="{!a.Product2Id}"/>
</apex:column>
<apex:column headerValue="Contract">
<apex:inputField value="{!a.Contract__c}"/>
</apex:column>
<apex:column headerValue="Version">
<apex:inputField value="{!a.Version__c}"/>
</apex:column>
<apex:column headerValue="Asset Start Date">
<apex:inputField value="{!a.Asset_Start_Date__c}"/>
</apex:column>
<apex:column headerValue="Asset End Date">
<apex:inputField value="{!a.Asset_End_Date__c}"/>
</apex:column>
<apex:column headerValue="PPT ID">
<apex:inputField value="{!a.PPT_ID__c}"/>
</apex:column>
<apex:column headerValue="Quantity">
<apex:inputField value="{!a.Quantity}"/>
</apex:column>
<apex:column headerValue="Tenant Name">
<apex:inputField value="{!a.Tentant_Name__c}"/>
</apex:column>
<apex:column headerValue="Status">
<apex:inputField value="{!a.Status}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks,

Aaron
scottbcovertscottbcovert
Hi Aaron,

Probably the easiest way would be to add another column that displays an apex:commandButton or apex:commandLink that passes in the record id to a clone method in your Apex controller. The method can then iterate through your record list to find the matching sObject record and make use of the .clone() SObject method (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_clone) to clone the record and rerender the table
Aaron Persich 8Aaron Persich 8
Thanks Scott,

I understand adding the new column and adding the header but how would I add the checkboxes for the users to select the line items?
scottbcovertscottbcovert
Hi Aaron,

You'll want to use a wrapper class and have another column for a checkbox:

http://mycloudexperience.blogspot.com/2011/03/adding-checkbox-on-pageblocktable.html
Aaron Persich 8Aaron Persich 8
Thanks I will give it a try
Aaron Persich 8Aaron Persich 8
One more question.  First your blog is awesome.  But where in my code should I add the wrapper class?
scottbcovertscottbcovert
Hi Aaron,

Thanks, but I can't take credit-that was a blog post from Nino Bustillos, but yes it is awesome :-) You'll most likely want to just add it to your Apex controller class; though you could also probably make it a standalone class of its own to be used by multiple controllers in the future.