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
Sahil YadavSahil Yadav 

How to Create Opportunity from Tasks whoId using button or action

I have a scenario where i need a button on task record which should directly create a opportunity based on whoid of a task where whoid is Contact .
How could we achieve this, basically  I tried this using flows but i couldn't able to achieve at the moment if any help would be apprechiable.
Create a quickAction on Task which calls an Aura or LWC component. Pass the current record Id(i.e. TaskId) from component to apex.
In the apex controller fetch the whoId by SOQL on Task with the passed on Id and create an Opportunity with the details you need. You can show a toast message to inform about the success/failure of the creation of that Opportunity.
mukesh guptamukesh gupta
Hi Shail,

If you are on a Task, why do you need to use a custom URL ?  Your users can just select the Opportunity from the Related To dropdown.
If you are on an Opportunity and click the "New Task" button, the RelatedTo is automatically populated.

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Sahil YadavSahil Yadav
Hello Mukesh, 
Rather than creating manually i want to automate that process that is my business requirement. I need to create a action which invoke a flow and I need to create an opportunity which specific name format that is AccountName-CampaignName-MonthofCampaign.
Any other way could you share so that I could reach you and hope you can assist me on creation of this business requirements.