0

Getting error with this code but I can't figure it out

trigger LeadConvert on Lead (after insert) {
    list leadsToConvert = new list();

    Database.LeadConvert lc;
    string convertedStatus = '';
    list convertStatusList = new list();
    convertStatusList = [Select Id, MasterLabel 
                        from LeadStatus where IsConverted=true limit 1];
    if(convertStatusList.size() > 0){
        convertedStatus = convertStatusList[0].MasterLabel;
        }
    else{ 
            convertedStatus = 'Closed - Converted'; 
        }

    for(Lead l : trigger.New){
        if(l.AutoConvert__c == true){
            lc = new database.LeadConvert();
            lc.setLeadId(l.ID);
            lc.setDoNotCreateOpportunity(true); 
            lc.setConvertedStatus(convertedStatus);
            leadsToConvert.add(lc);
        }
    }

    list lcrList = new list();
    lcrList = Database.convertLead(leadsToConvert);
}
  • @AdrianLarson Should this really be a duplicate of the linked question? – sfdcfox Jun 8 '17 at 15:59
1

The problem is with your List declaration. In some programming languages you can probably just write

list mylist = new list();

But not in Apex. Here you should also specify the object type between <> right after the List, for example:

List<Lead> leadsToConvert = new List<Lead>();

Also, you do not have to initialize a new list and then perform a query, so you can rewrite these 2 lines:

list convertStatusList = new list();
convertStatusList = [Select Id, MasterLabel 
                    from LeadStatus where IsConverted=true limit 1];

to just 1 line:

List<LeadStatus> convertStatusList = [SELECT Id, MasterLabel 
                                      FROM LeadStatus WHERE IsConverted=true LIMIT 1];
|improve this answer|||||
  • You're the man thank you so much for the explanation – user3096728 Sep 17 '15 at 16:41
2

List is a generic class that requires a data type; use somethng like List<Lead> for leads, or List<String> for a list of Strings.

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.