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
Bahtiyar IshkabulovBahtiyar Ishkabulov 

Move Opportunity Product record to the Cancelled Opportunity Product

Hi everyone,
We created custom object Calcelled Opportunity Product (CancelledOpportunityLineItem__c) where we want to store opportunity products, that were initially present in customer's inquiry but then removed from it for some reason (master-detail relationship with Opportunity object). Now we want to have a button "Cancel Product" on the standard Opportunity Product's detail page that will move the product to the Cancelled Opportunity Products (delete the record from the OpportunityLineItem object and create new record in the CancelledOpportunityLineItem__c object). Also we want a separate window to appear before that, where user will input cancelling reason. Can anyone explain me, wich Salesforce platform tools should we use for this task?
Jolly_BirdiJolly_Birdi
Hello @Bahtiyar

You can use Flows for this. Let me know if you have any doubt while creating it.

Thanks.
Bahtiyar IshkabulovBahtiyar Ishkabulov
@Jolly_Birdi
I created a flow, but how can I add a button on the Opportunity Product's detail page, that will run this flow and send the record id as a parameter to flow's variable?
Jolly_BirdiJolly_Birdi
Hello @Bahtiyar

You can add a Javascript Button and call the flow using URLUser-added image

Please mark this best and like the answer if you find it useful.

Thanks,
Jolly Birdi
Bahtiyar IshkabulovBahtiyar Ishkabulov
@Jolly_Birdi
We use Lightning, so is there any alternative to javascript button in this case? Thank you very much for help!
Jolly_BirdiJolly_Birdi
@Bahtiyar

For Lightning You need to create an action on Opportunity and from there you need to fetch the details of OppLineItems and then call the flow for selected records.

Thanks.
Bahtiyar IshkabulovBahtiyar Ishkabulov
@Jolli_Birdi Thank you for reply. So isn’t it possible to place a button or do anything else to allow users to run that flow from Opportunity Product detail page? And how do I fetch details of OpportunityLineItems from Opportunity? As I understand, the first step of the flow should contain a screen where I ask user to select items that he wants to cancel. But I don’t understand how to do this.
Jolly_BirdiJolly_Birdi
@Bahtiyar

Flow Would be better if it would be for the classic. In the lightning experience you can pass the OpplineItem id to class and directly create a new records as you want. It would be easiest way for this.
 
Bahtiyar IshkabulovBahtiyar Ishkabulov
@Jolly_Birdi You mean to write a code in an Apex class? That would be great, but I still don’t understand how to invoke that class and pass some parameters to it from OpportunityLineItem page?
Jolly_BirdiJolly_Birdi
You need to add the action on the Opportunity. From the OpportunityId you can get its related all OppLineItems. Everything would be happened on the Opportunity Page. From the Selected OppLineItems you can canceled the OppLineItems and create a new rows in your custom object.

Please like and mark it helpful, If you find it positive.

Thanks.