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
withoutmewithoutme 

Clone button

In opportunitues, you have a "clone with Products" and a "clone without products".

This creates a new opportunity with the same opp and products data.

 

What if I want to clone button, but the result is another custom object (invoice) with "opp clone with products" as the details.

 

How would I go abt doing this?

1. Create the invoice custom object with all opp fields. Can I set products as detail of invoice so that I can copy the products too?

2. Create a vf page with extension of opportunity standard controller. In the extension, how do I get the process the clone logic?

 

Please help. Thank you

Ron HessRon Hess

this app

 

http://sites.force.com/appexchange/apex/listingDetail?listingId=a0N300000016ce6EAA

 

has an example of clone with products (all the apex code you need), it's un-managed so you can install it in your DE org and copy what you need.

withoutmewithoutme

Thanks Ron. That was what i was looking for.

Also, I wrote a simple apex class to just see how this is done. It doesn't copy the detail records, but can be extended. This is what I wrote.

 

 

public class cloneclass { private final ApexPages.StandardController cloneclassEx; public cloneclass(ApexPages.StandardController stdController) { cloneclassEx = stdController; } public PageReference autoRun(){ //first get the opportunity we are cloning Opportunity thisOpp = [select id, Name, Amount, Description, CloseDate, AccountId from Opportunity where Id = :cloneclassEx.getId()]; if(thisOpp.id==null) return null; Sales_Invoice__c inv = new Sales_Invoice__c(); inv.Amount__c = thisopp.Amount; inv.Close_Date__c = thisopp.CloseDate; inv.Description__c = thisopp.Description; inv.Account__c = thisopp.AccountId; inv.Name = thisopp.Name; insert inv; PageReference retpage = new PageReference('/'+inv.id); retpage.setRedirect(true); return retpage; } }

 

 In opportunities, the clone button drops down to "clone with products" and "clone without products". Is there a way ot mimic this drop down? I remember seeing this in one of the tutorials in dreamforce but cant seem to find it.

And your webinar yesterday was awesome!

 

Ron HessRon Hess
No, that button is special.  You will have to re-create it yourself using HTML and DHTML, would be a great component to share if you do !