1

Documentation says it should be public, but getting an error:

Method does not exist or incorrect signature: void setOpportunityId(Id) from the type Database.LeadConvert

Any ideas why this method wouldn't be available?

Sample example:

Opportunity newOpp = new Opportunity();
insert newOpp;

Database.LeadConvert leadConvertCls = new Database.LeadConvert();

//This works fine
leadConvertCls.setLeadId(myLead.Id);

//Error when saving to org:
//Method does not exist or incorrect signature: void setOpportunityId(Id) from the type Database.LeadConvert (186:28)
leadConvertCls.setOpportunityId(newOpp.Id);

Database.LeadConvertResult conversionResult = Database.convertLead(leadConvertCls);
5
  • Does this answer your question? How to convert a lead to a new opportunity in Apex
    – identigral
    Commented Feb 16, 2022 at 18:35
  • 2
    Welcome to SFSE. Please take a moment to read How to Ask and take the tour. Please edit your post to include the relevant code and context. Note that if the id parameter is null, you will get this error. Commented Feb 16, 2022 at 18:42
  • @identigral I'm confused as to why you think that's a related question (other than it hitting the keywords "lead" and "convert").
    – Derek F
    Commented Feb 16, 2022 at 18:44
  • Can you please post atleast the code snippet where you are facing the issue. I have used this method earlier and didn't find any issues.
    – Saroj Bera
    Commented Feb 16, 2022 at 18:54
  • @SarojBera I added a code snippet to the question. Hopefully that provides some additional detail!
    – Austin
    Commented Feb 16, 2022 at 19:43

1 Answer 1

3

This method has not always been available; it was added in Spring 18. Please check your Apex class' API version, and set it to at least version 42.0. You can find this setting in the Developer Console when you open the class, or in the ClassName.cls-meta.xml file in a SFDX repository or MDAPI repository.

2
  • 2
    There it is! I completely forgot that this is an older API version. Thank you!
    – Austin
    Commented Feb 16, 2022 at 20:13
  • @Austin yeah, we've all done that at least once. Comes with the territory.
    – sfdcfox
    Commented Feb 16, 2022 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .