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
Pankaj Singh 216Pankaj Singh 216 

how to convert lead through apex using this custom button

User-added image
Chris EagerChris Eager
It would help if you added some context around what you are actually trying to do? Is that a button on another object? Do you want to add that button to the Lead? Are you using approval processes? 

But you can use this class (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_convertLead.htm) to convert a lead.
Pankaj Singh 216Pankaj Singh 216
no this is button on custom object and through this I want to convert lead. and if any probelm in converting lead then some other filed are there and error mesage should be populate in that field.
Chris EagerChris Eager
Gotcha. Then you could either create a checkbox on the Lead "Convert Lead" and a trigger that would convert the lead for you. This would allow you to have some more flexability, but might make your error handling a little more difficult to show on that page. Or you could create a LWC or VF Page that calls apex that would convert the lead using the link above.
Pankaj Singh 216Pankaj Singh 216
I want to achieve this whole functionality through lightning component. but i am facing issue in achieving error. i have wriiten convert lead code but still i am facing issue.