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 

Clone Asset Line Items

Hello,
 
I would like to create a “Clone” button on the Asset related list where the user can select the assets then hit the clone button to clone the assets.  I am assuming I need to create a visualforce page but I am not sure where to begin.  Any help would be much appreciated.
 
Thanks,
 
Aaron 
AshlekhAshlekh
Hi,

1) Create a class and define a webservice method which take a list of record ids in the partameter and write a logic in that method for clonng the record.

2) Just create a list button on the object (whose record your showing in related list). At the time of creating list button there will be an option "Display Checkboxes (for Multi-" check this check box.

In the List button you can get the all records id which is selected by user throuth this this 
var selectedRecords = {!GETRECORDIDS($ObjectType.YOUROBJECTAPINAME)};
Now "selectedRecords" contains the id's of the record and now you need to send/pass these id to your controller.

Here is blog by which you see how call a class method in list button.

http://blog.shivanathd.com/2014/07/call-apex-class-from-custom-button-salesforce.html

-Thanks
Ashlekh Gera
 
Aaron Persich 8Aaron Persich 8
Hi ASklekh,

Thank you for your response.  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>