You need to sign in to do that
Don't have an account?
Aaron 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
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
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
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?
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
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.