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
Tommy CTommy C 

Creating a button to create custom objects for a child Opportunity based off the Products of its parent Opp?

I have an object called Past Products that is normally created when a new child Opportunity is created. These Past Products objects are associated with the child Opp and are created from the parent Opportunity's Products. Currently, there is a code that creates these Past Products when a new child Opportunity is created from its parent. However, if the child Opportunity is created separately and is assigned a parent afterwards, these Renewals are not created. These Past Products show up in a Related Record List for the child Opportunity.   

Essentially, given the child Opportunity, I want to pull all the Products from the parent Opportunity and create Past Products objects for each of those products and associate these Past Product objects with the child Opportunity.  I want to be able to add a button or some trigger to manually call this method. The code already exists to create these Past Product objects so it's either a matter of calling this method or replicating its function.  

Would it be possible to call this Apex method from the Process Builder or a Button? Could it be done through a workflow? If I can also replicate what the code does (creating the Past Product objects) in Process Builder or a Workflow without needing to call the method, that also works. I'm new to the platform so I will appreciate any help!