Posts

Showing posts from September, 2017

Custom button on Opportunity to clone opportunity with its related List (object)

Create a new Detail Page Button on the Opportunity object. Set Behavior to Execute JavaScript and Content Source to OnClick JavaScript Paste the Below snippet of code in the window {!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")}  {!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}  var retStr;  retStr = sforce.apex.execute(" CloneOpportunitywithRelatedObject "," cloneOpportunity ",  {oppId:"{!Opportunity.Id}"});  location.replace('/' + retStr);   Create a new Apex class and paste the below snippet of code global class  CloneOpportunitywithRelatedObject  {     webservice static Id  cloneOpportunity (Id oppId) //  pass parameters     {         List < Related_Object__C > relatedList = new List < Related_Object__C > ();   // query all the fields you need to clone          Opportunity opp = [SELECT ID, CloseDate, StageName, Type, Name FROM Opportunity                                        WHERE Id =: oppId