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
tracypjohnstontracypjohnston 

Apex Class and Aura Component Bundle Functionality

I'll start by saying, I'm not a developer.  I'm doing some work for a customer that had a previous company do some work for them, and I'm trying to figure out what they did (and why).

In their partial sandbox, they created an Apex Class (called LeadConversionController).  To me (again, a non-developer) it looks like it just controls where the fields are mapped when a lead is converted.  I tried to delete it, but it can't be deleted because of an "Aura Component Bundle".  When I go to the Aura Component Bundle, it takes me to the Developer Console and that's where it loses me.  I have no idea what I'm looking at.

I know you can't deactivate an Apex Class, but what can I do if I can't delete it?  I also don't see how to get rid of the Bundle. 

Do I just refresh the sandbox and lose whatever it is that they wrote in that Class?  

Why would an Apex Class be written to handle the field conversion?  There is nothing special about the set up (Lead to Account, Contact and Opportunity).

I can show the code if anyone (1) made it this far into my post and (2) can tell me if I'm missing something in the code.

Thank you!
sooraj kesavadassooraj kesavadas
If you can post the code, I am sure someone can definitely help you to understand what it is doing. 

Regarding the Apex class, since it is being referred in the Aura component, you will have to remove the reference first before you can delete the Apex class or you can comment out most of the Apex class but that could lead to Lead conversion to fail.

I believe the Convert button you currently have on the Lead page layout is a custom button that is calling the Aura component and in turn Apex class. If you would like to revert to the standard Lead conversion process, you can update the lead page layout and remove the custom convert button and add the standard convert button to it.
tracypjohnstontracypjohnston
Thank you @Sooraj Kesavadas!

The code is so long, I can only post 1/2 in an answer.  Here is the first half:


public class LeadConversionController {
   
    @AuraEnabled
   
    public static Lead getLeadDetails (Id leadId){
       
        return [SELECT Name, Email, Phone From Lead WHERE ID =: leadId];
       
    }
   
    @AuraEnabled
   
    public Static List<Contact> getContact(Id leadId){
       
        Lead l =[SELECT Email  from Lead Where Id =: leadId];
       
        List<Contact> conList =[SELECT Id, Name,Email, Phone From Contact Where Email =: l.Email];
       
        system.debug('conList'+ conList);
       
        return conList;
       
    }
   
    @AuraEnabled
   
    public static void updateLead(Id leadId){
       
        Id landRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Land').getRecordTypeId();
       
        Id PropertyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Property').getRecordTypeId();
       
        Database.LeadConvert lc = new database.LeadConvert();
       
        lc.setLeadId(leadId);
       
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
       
        lc.setConvertedStatus(convertStatus.MasterLabel);
       
        Database.LeadConvertResult lcr = Database.convertLead(lc);
       
        System.debug(lcr);
       
        Lead l =[SELECT Name, Address,Property_Type__c,Comments__c,County__c,Current_Zoning__c,Description_Notes__c,Email,
                
                 Floodplain__c,Floodplain_Type__c,GIS_Topography__c,Gross_Building_Sq_Ft__c,Lease_Type__c,Lot_Size__c,
                
                 of_Dock_Doors__c,Outside_Storage__c,Parent_Lead__c,Previous_Tenant_Business_Operations_if__c,Sewer_Availability__c,
                
                 Sewer_Distance_from_Property__c,Sewer_Size__c,Tenancy__c,Thoroughfare_Map__c,Total_Building_SF__c,Total_Warehouse_SF__c,
                
                 Total_Office_SF__c,Year_Built__c,Zoning__c,Phone,Company,Contact_Type__c,LastName, FirstName,Salutation, Property_City_Limits__c,
                 
                 Clear_Height__c,Street,City,Country,PostalCode,ConvertedContactId,ConvertedOpportunityId, ConvertedAccountId, OwnerId, RecordType.Name,
                
                 Water_Availability__c, Water_Distance_from_Property__c, Sprinklered__c, Construction_Type__c FROM Lead WHERE Id =: leadId ];
       
        // Update the Account information from Lead
       
        Account acc = new Account ();
       
        acc.Id = lcr.getAccountId();
       
        acc.Name = l.Street+' '+l.City;
       
        if(l.RecordType.Name =='Land'){
           
            acc.RecordTypeId = landRecordTypeId;
           
            acc.Type__c = 'Land';
           
        }
       
        else {  
            
            acc.RecordTypeId = PropertyRecordTypeId;
           
            acc.Type__c = 'Property';
           
        }
       
        acc.Clear_Height__c = l.Clear_Height__c;
       
        acc.Comments__c = l.Comments__c;
       
        acc.County__c = l.County__c;
       
        acc.Current_Zoning__c = l.Current_Zoning__c;
       
        acc.Description_Notes__c = l.Description_Notes__c;
       
        acc.Email__c = l.Email;
       
        acc.Floodplain__c = l.Floodplain__c;
       
        acc.Floodplain_Type__c = l.Floodplain_Type__c;
       
        acc.GIS_Topography__c = l.GIS_Topography__c;
       
        acc.Gross_Building_Sq_Ft__c = l.Gross_Building_Sq_Ft__c;
       
        acc.Lease_Type__c = l.Lease_Type__c;
       
        acc.Lot_Size__c = l.Lot_Size__c;
       
        acc.of_Dock_Doors__c = l.of_Dock_Doors__c;
       
        acc.Outside_Storage__c = l.Outside_Storage__c;
       
        acc.Parent_Lead__c = l.Parent_lead__c;
       
        acc.Previous_Tenant_Business_Operation__c = l.Previous_Tenant_Business_Operations_if__c;
       
        acc.Sewer_Availability__c = l.Sewer_Availability__c;
       
        acc.Sewer_Distance_from_Property__c = l.Sewer_Distance_from_Property__c;
       
        acc.Sewer_Size__c = l.Sewer_Size__c;
       
        acc.Tenancy__c = l.Tenancy__c;
       
        acc.Thoroughfare_Map__c = l.Thoroughfare_Map__c;
        
        acc.Total_Building_SF__c = l.Total_Building_SF__c;
       
        acc.Total_Office_SF__c= l.Total_Office_SF__c;
       
        acc.Total_Warehouse_SF__c = l.Total_Warehouse_SF__c;
       
        acc.Year_Built__c = l.Year_Built__c;
       
        acc.Zoning__c = l.Zoning__c;
       
        acc.Parent_Lead__c = l.Id;
       
        acc.Property_City_Limits__c = l.Property_City_Limits__c;
       
        acc.Sprinklered__c = l.Sprinklered__c;
       
        acc.Property_Type__c = l.Property_Type__c;
       
        acc.Water_Availability__c = l.Water_Availability__c;
       
        acc.Water_Distance_from_Property__c = l.Water_Distance_from_Property__c;
       
        acc.Construction_Type__c = l.Construction_Type__c;
       
        update acc;
       
        // Update the contact information from Lead     
        Contact con = new Contact ();
       
        con.Id = lcr.getContactId();
       
        con.AccountId = acc.Id;
       
        con.Email = l.Email;
       
        con.Phone = l.Phone;
       
        con.LastName = l.LastName;
       
        con.FirstName = l.FirstName;
       
        con.Salutation = l.Salutation;
       
        con.Company__c = l.Company;
       
        con.Contact_Type__c = 'Sales';
       
        update con; 
       
        // Update Opportunity from Lead
        Opportunity opp = new Opportunity();
       
        opp.Id = lcr.getOpportunityId();
       
        opp.Name = l.Street + ' ' + l.City + ' - ' + l.RecordType.Name;
       
        opp.StageName = 'New / Interest';
       
        update opp;
       
    }
 
tracypjohnstontracypjohnston
Second Portion:


    @AuraEnabled
   
    public static void convertLead (Id leadId, Id contactId){
       
        Id landRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Land').getRecordTypeId();
       
        Id PropertyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Property').getRecordTypeId();
       
        Database.LeadConvert lc = new database.LeadConvert();
       
        lc.setLeadId(leadId);
       
        lc.setContactId(contactId);
       
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
       
        lc.setConvertedStatus(convertStatus.MasterLabel);
       
        Database.LeadConvertResult lcr = Database.convertLead(lc);
       
        System.debug(lcr);
       
        Lead l =[SELECT Name, Address,Property_Type__c,Comments__c,County__c,Current_Zoning__c,Description_Notes__c,Email,
                
                 Floodplain__c,Floodplain_Type__c,GIS_Topography__c,Gross_Building_Sq_Ft__c,Lease_Type__c,Lot_Size__c,
                
                 of_Dock_Doors__c,Outside_Storage__c,Parent_Lead__c,Previous_Tenant_Business_Operations_if__c,Sewer_Availability__c,
                
                 Sewer_Distance_from_Property__c,Sewer_Size__c,Tenancy__c,Thoroughfare_Map__c,Total_Building_SF__c,Total_Warehouse_SF__c,
                
                 Total_Office_SF__c,Year_Built__c,Zoning__c,Phone,Company,Contact_Type__c,LastName, FirstName,Salutation, Property_City_Limits__c,
                
                 Clear_Height__c,Street,City,Country,PostalCode,ConvertedContactId,ConvertedOpportunityId, ConvertedAccountId, OwnerId, RecordType.Name,
                 
                 Water_Availability__c, Water_Distance_from_Property__c, Sprinklered__c, Construction_Type__c FROM Lead WHERE Id =: leadId ];
       
        // Update the Account information from Lead
       
        Account acc = new Account ();
       
        acc.Id = lcr.getAccountId();
       
        acc.Name = l.Street+' '+l.City;
       
        if(l.RecordType.Name =='Land'){
           
            acc.RecordTypeId = landRecordTypeId;
           
            acc.Type__c = 'Land';
           
        }
       
        else {  
           
            acc.RecordTypeId = PropertyRecordTypeId;
           
            acc.Type__c = 'Property';
           
        }
       
        acc.Clear_Height__c = l.Clear_Height__c;
       
        acc.Comments__c = l.Comments__c;
       
        acc.County__c = l.County__c;
       
        acc.Current_Zoning__c = l.Current_Zoning__c;
       
        acc.Description_Notes__c = l.Description_Notes__c;
       
        acc.Email__c = l.Email;
       
        acc.Floodplain__c = l.Floodplain__c;
       
        acc.Floodplain_Type__c = l.Floodplain_Type__c;
       
        acc.GIS_Topography__c = l.GIS_Topography__c;
       
        acc.Gross_Building_Sq_Ft__c = l.Gross_Building_Sq_Ft__c;
       
        acc.Lease_Type__c = l.Lease_Type__c;
       
        acc.Lot_Size__c = l.Lot_Size__c;
       
        acc.of_Dock_Doors__c = l.of_Dock_Doors__c;
       
        acc.Outside_Storage__c = l.Outside_Storage__c;
       
        acc.Parent_Lead__c = l.Parent_lead__c;
       
        acc.Previous_Tenant_Business_Operation__c = l.Previous_Tenant_Business_Operations_if__c;
       
        acc.Sewer_Availability__c = l.Sewer_Availability__c;
       
        acc.Sewer_Distance_from_Property__c = l.Sewer_Distance_from_Property__c;
       
        acc.Sewer_Size__c = l.Sewer_Size__c;
       
        acc.Tenancy__c = l.Tenancy__c;
        acc.Thoroughfare_Map__c = l.Thoroughfare_Map__c;
        acc.Total_Building_SF__c = l.Total_Building_SF__c;
        acc.Total_Office_SF__c= l.Total_Office_SF__c;
        acc.Total_Warehouse_SF__c = l.Total_Warehouse_SF__c;
        acc.Year_Built__c = l.Year_Built__c;
        acc.Zoning__c = l.Zoning__c;
        acc.Parent_Lead__c = l.Id;
        acc.Property_City_Limits__c = l.Property_City_Limits__c;
        acc.Sprinklered__c = l.Sprinklered__c;
        acc.Property_Type__c = l.Property_Type__c;
        acc.Water_Availability__c = l.Water_Availability__c;
        acc.Water_Distance_from_Property__c = l.Water_Distance_from_Property__c;
        acc.Construction_Type__c = l.Construction_Type__c;
        update acc;
        Opportunity opp = new Opportunity();
        opp.Id = lcr.getOpportunityId();
        opp.Name = l.Street + ' ' + l.City + ' - ' + l.RecordType.Name;
        opp.StageName = 'New / Interest';
        update opp;  
    } 
}
sooraj kesavadassooraj kesavadas

@tracypjohnstonThe only thing that stands out in the above code is, during conversion, based on the Lead's Record type, the Account's RecordType is selected which cannot be done using the standard Lead Conversion process. Also Opportunity.Name is a combination of three fields from Lead which is also not supported by the out-of-the-box field.

For testing, From the Lead page layout in a Sandbox, you should be able to remove the custom 'Convert' button and add the out-of-the-box 'Convert' button and test if the functionality is working as expected, and then decide which Convert button to use going forward.

tracypjohnstontracypjohnston
@sooraj kesavadas Thank you so much for looking at this!  Sorry for the delayed response, but it is very appreciated!