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
dcarmen66dcarmen66 

Clone Opportunity Button

It looks like the standard Clone button on the Opportunity only clones the fields that are part of the current page layout. Can anyone tell me if I'm correct in that assumption? I have fields on the Opportunity that I need to be cloned that are not part of the layout. Will I need to override the button in order to use the Apex clone method? Has anyone seen this or have any other solutions for this?

Thanks!

Dan

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

When you clone any record only the part on detail is cloned. So only the field on layout will be cloned. Even in Apex also it works like that see an Example :

 

I have a Contact c with FirstName = 'TestFirstName' , and LastName='TestLastName'

 

in My apex

 

Contact con = [Select LastName from Contact where LastName='TestLastName' limit 1];

Contact cloneofCon = c.clone(false);

insert cloneofCon;

 

now in above cloneofCon will not have first name as TestFirstName, first name will be null but if I do this

 

//queries  first name also

Contact con = [Select LastName , Firstname from Contact where LastName='TestLastName' limit 1];

Contact cloneofCon = c.clone(false);

insert cloneofCon;

 

now i wil have firstname also

 

Now to solve your issue you can create a VFP and Overrride your Clone button , pass the id of your opportunity as query parameter , in page level action ( write a method in controller for this page level action)  just fetch all the fields of opportunity and clone .

 

Let me know if any issues in it.

All Answers

Shashikant SharmaShashikant Sharma

When you clone any record only the part on detail is cloned. So only the field on layout will be cloned. Even in Apex also it works like that see an Example :

 

I have a Contact c with FirstName = 'TestFirstName' , and LastName='TestLastName'

 

in My apex

 

Contact con = [Select LastName from Contact where LastName='TestLastName' limit 1];

Contact cloneofCon = c.clone(false);

insert cloneofCon;

 

now in above cloneofCon will not have first name as TestFirstName, first name will be null but if I do this

 

//queries  first name also

Contact con = [Select LastName , Firstname from Contact where LastName='TestLastName' limit 1];

Contact cloneofCon = c.clone(false);

insert cloneofCon;

 

now i wil have firstname also

 

Now to solve your issue you can create a VFP and Overrride your Clone button , pass the id of your opportunity as query parameter , in page level action ( write a method in controller for this page level action)  just fetch all the fields of opportunity and clone .

 

Let me know if any issues in it.

This was selected as the best answer
dcarmen66dcarmen66

That's what I was thinking but hoping it was otherwise :-) Thanks for your reply!

Roger WickiRoger Wicki
@Shashikant Sharma

Are you kidding me? Is this still the case? Why is it called clone if it does not clone but create a look-alike for the opportunity!?!?

I really hope that behaviour changed since 2011...
Andrew Henderson 6Andrew Henderson 6
This is still how Salesforce works with the off-the-shelf Clone button. Doesn't make any sense to me either.  In my case there are fields that I specifically don't want a user to see but that I was expecting to get repliced to a new record with the Clone button.   Learning that those fields have to be on the page layout is very annoying.   Not sure what the developers where thinking on this one.