Advertisements
<
  • Khing Sodapop

    It’s working and very useful. Thank you for sharing.

  • Craig Maxwell

    Hey Rakesh,
    First of all, thank you so much for sharing this!!!

    I did have a quick question and I was hoping you could help… The issue I’m running into is when this process is triggered off by our engineering team (It works fine if I manually trigger the flow) but whenever they fire it off it gives an error like this…

    Executed the default outcome
    AUTOCONVERTLEADS (APEX): myRule_1_A1
    Inputs:
    LeadIds = {!myVariable_current.Id} (00Q9E000005HuWLUA0)
    Error Occurred: An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Converted objects can only be owned by users. If the lead is not owned by a user, you must specify a user for the Owner field.: [OwnerId]

    Do I need to include the OwnerId in the apex variables? 😱

    Thanks in advance!

  • Joseph Nammour

    Hi Rakesh, thank you so much for this code. It works for me on my staging site but I am running into an issue with code coverage. It basically only says it has 25% code coverage and you need at least 75% to move it to production. Do you have any suggestions for how I can get it to 75%? Did you ever run into this issue?

  • Jonathan

    Hello Rakesh,

    Thank you for this post. It has been very helpful and is relevant for a similar problem I’m trying hard to solve. However, I’m still really struggling to get to exactly where I need and I hoping that if possible, you could kindly post a variation of the code that would allow for an additional variable(s) to be passed to the class from another field on the same lead. In particular, I’m intending to store an existing contact’s id (and that contact’s related account ID) on the Lead, so that when the process builder triggers the Apex Class it converts that lead to an existing contact as already specified on a field in that lead.

    I suspect I need some code like below but also some code to get the variables from the Process Builder to the Apex Class for it to reference/use

    – Leadconvert.setContactId(StoredContactId on currentlead)
    – Leadconvert.setAccountId(StorcdAccountId on currentlead)

    Thank you in advance,
    Jonathan

  • Nick

    Thanks for this post, code worked like a charm, was able to trigger rest of Lead Conversion Flow by IsConvert Process Builder criteria and then autolaunched flow to create related Account and Opportunity to complete a custom Lead conversion flow. 🙂 thank you.

  • Korhan

    Hi Rakesh, I tried your workaround but it gives me this error.

    An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: INVALID_STATUS, invalid convertedStatus: Ready to Check: [Status]

    Do I need to modify this line? (I’m a newby by the way)

    Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);

    Thanks

  • sushmitha

    Hi Rakesh, I used this apex code and the test class. I need to access the opportunity id and the account id after conversion. I understand that I will have another variable in the flow that will accept the opportunity id and i can pass it through the getOpportunityId() method. Is there anything else needed for the apex class for the same

  • Adriana Voyce

    This is cool, I tried it and it worked, I have leads auto converting based on certain criteria… Is there any way that when it converts it can match to an account based on the account website?

  • Rick Haag

    Rakesh, thank you so much for posting this! It is super cool that you posted the test class with it. It saved me hours.

    Looking forward to more of these types of posts in the future.

  • harmonynewtechnologies

    Hi Rakesh,

    Great post!

    Question, if I set up a web to lead method, will the conversion process you set up work in this scenario?

    Thanks!

  • Jeffruy Examene

    How do you prevent duplicates with this method

  • Rudy Ornelas (@crmpanda)

    Hi Rakesh, Do you happen to have the test class for this example? Great example btw

  • Jon

    Great post! Thanks for this.

    How do I use this to convert leads to contacts on existing accounts where DUNS match across both lead and account?

  • Jon

    Hello!

    I’m auto converting leads to Contacts on existing accounts that have a matched D-U-N-S. I have a flow built out to loop through and find a matched account and then assigns a variable, how do I use this account ID variable {!SobjAccountwithMatchedDuns.Id} in this lead convert Class?

    Or would it be easier to just modify this code to do all of it?

    Thanks!

  • Dnyaneshwar

    Hi,

    I have visual force page embedded in Lead page layout. Upon conversion its showing :Record type unavailable error.

    I have default record types in place for all objects and also person account is enabled. So i am thinking the error is due to VF page in lead layout, I am correct? Do you know any workaround for the error.

    Thanks a ton!

  • David Brenner

    Thanks so much for this! Another internal client satisfied, thanks to you!!

  • Cassio

    Hiya, we’ve implemented this solution, and it works great for newly created leads, but for updating leads it seems to cause an error.

    We get:

    The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 301260000009Tap. Contact your administrator for help.

    This only happens with previously created leads, not with new leads. We have set up the process builder workflow to trigger on a checkbox being ticked.

    Any help appreciated.

    Tom and Cassio

  • Jennifer Buchanan

    I’m trying to use this in Lightning and while it does convert, I get an error when the page refreshes that the lead has already been converted. What would I need to add to redirect to the opportunity page that was created upon conversion? Thanks in advance!

  • Syed

    Hi Rakesh,

    I tried your method. I am getting the following error from the process builder
    An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, valid leadId is required: []

    Also I am have a business process that creates person account and opportunity once the lead is converted

    Any suggestions will be vary valuable.

    thank you

  • Pingback: Admin Hack: Auto Convert Leads to Salespeople - Cirrus Insight

  • Brenda Frambes

    This is fantastic!! Thank you.

  • Stefan Bennett

    I’m very excited to implement this. I went through the process you laid out and when testing I received the following errors. Any insight?

    An error occurred at element myRule_1_A1 (FlowActionCall).
    An Apex error occurred: System.DmlException: ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, valid leadId is required: []

  • Em

    Hi,

    After implementing leads can not convert error is CANNOT_UPDATE_CONVERTED_LEAD, could you help me with some solution?

  • Janet

    Hi

    Are these records automatically assigned to the owner of the lead? What if we wanted to auto-assign the lead creation to a certain individual? Or how about auto-associate to an existing account?

  • Jaime Curiel Acosta

    Great post, Rakesh, really helpful!
    I have implemented this in my organization and it works as expected 🙂
    I just have a question regarding it, does it work for mass conversions? When converting several leads at a time it seems to convert only one of them but does nothing with the others. Is there something that can be done to make it work for several leads at a time?
    Thanks!

  • Fabian

    That is really good, do I need to do something special in order to test the method with @InvocableMethod annotation?
    and personal question, do you believe there is any advantages in using the process builder instead of triggering this from a trigger?, I am just asking this as I am having some issues with process builder when trigger from a bulk upload/edit, unless this bulk upload is done 1 by 1

  • Mohammed Hassan

    This is amazing, superstar, thanks so much appreciate this Rakesh.

  • Leave a Reply to Jeffruy Examene Cancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • %d bloggers like this: