• Danielle Pulley 10
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
I tried deploying my test coverage for autolead convertion. below is the error I am recieving. Is there something with my code? 


Error:
System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, convertedStatus is required.: [Status] 
Stack Trace: Class.TEST_LeadConvert.myUnitTest: line 17, column 1



CODE:

@IsTest private class TEST_LeadConvert{


private static testMethod void myUnitTest() {

// create a Lead
Lead lead=new Lead(LastName='Doe',FirstName='John',Company='Test',Status='New', );

insert lead;                

Database.LeadConvert lc = new database.LeadConvert();

//////////////////////////////////////////
lc.setLeadId(lead.id); //etc
//////////////////////////////////////////

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}}


Thank you in advanced!
I recently tried to push code from my sandbox to production and recieved an erro saying I only had 74% coverage and need 75%. Also, my trigger has 0% coverage. I am new to apex but can anyone help me understand why this is failing or how to correct it. Below is my trigger and class I created to convert Leads. 

Trigger: 
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
 if((myLead.isconverted==false) && (myLead.LeadSource == 'Academy Registration'||
 myLead.LeadSource == 'User Registration' || myLead.LeadSource == 'Organization Registration')) {
Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Qualified';
        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(true);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        }
        }
}


Class: 
public class LeadClass {
    public static void doConvert(Id leadId){ 
    Database.LeadConvert lc = new Database.LeadConvert();
    lc.setLeadId(leadId);

    Lead convertStatus = [SELECT Id,  LeadSource FROM Lead WHERE LeadSource = 'Academy Registration ' LIMIT 1];
    lc.setConvertedStatus(convertStatus.LeadSource);

    Database.LeadConvertResult lcr = Database.convertLead(lc);
    System.assert(lcr.isSuccess());
    }
}


All help is appreciated!

Thanks, 

Dani
Here is my trigger. I am not sure how to reference 3 different lead sources for the Lead to sutomatically convert. 

I need only the Leads whose lead source = Academy Regisatration, User Registration or  Organization Registration. 

Any help is appreciated!




I now got it to work. But how do I add more than one lead source? I only want it to run when the lead source is Academy Registration, User Registration or Organization Registration. 

trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
 if((myLead.isconverted==false) && (myLead.LeadSource = 'Academy Registration')) {
Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Qualified';
        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(true);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        }
        }
}
Hello,

is there a way way to convert a lead that comes in from web to lead automatically? 
If the lead status is new and lead source is advertisement then we want the lead to convert automatically into an account  and contact but not an opportunity. 

I am new to apex and figure this this may need code, how should this be written or is it possible? 

Thanks, 
Danielle

 
I recently tried to push code from my sandbox to production and recieved an erro saying I only had 74% coverage and need 75%. Also, my trigger has 0% coverage. I am new to apex but can anyone help me understand why this is failing or how to correct it. Below is my trigger and class I created to convert Leads. 

Trigger: 
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
 if((myLead.isconverted==false) && (myLead.LeadSource == 'Academy Registration'||
 myLead.LeadSource == 'User Registration' || myLead.LeadSource == 'Organization Registration')) {
Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Qualified';
        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(true);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        }
        }
}


Class: 
public class LeadClass {
    public static void doConvert(Id leadId){ 
    Database.LeadConvert lc = new Database.LeadConvert();
    lc.setLeadId(leadId);

    Lead convertStatus = [SELECT Id,  LeadSource FROM Lead WHERE LeadSource = 'Academy Registration ' LIMIT 1];
    lc.setConvertedStatus(convertStatus.LeadSource);

    Database.LeadConvertResult lcr = Database.convertLead(lc);
    System.assert(lcr.isSuccess());
    }
}


All help is appreciated!

Thanks, 

Dani
Hello,

is there a way way to convert a lead that comes in from web to lead automatically? 
If the lead status is new and lead source is advertisement then we want the lead to convert automatically into an account  and contact but not an opportunity. 

I am new to apex and figure this this may need code, how should this be written or is it possible? 

Thanks, 
Danielle

 

Does anyone know how I'd go about creating a trigger to convert a lead to an account contact and oppty, based upon a field in the lead?  For example, A lead score of > 30, I'd like to trigger the lead to automatically convert, and kick off a notification email. 

 

Has anyone done this before?

 

Thanks!

Chris

I finally got Validation/Triggers enabled for Lead Conversion, but now I can't figure out how to code a trigger for it.  I've tried

Code:
trigger test on Lead (after convert) {
}

but I get an Invalid Token error.  There are no hints in the documentation.

thanks
David