• Jeremy Bannon
  • NEWBIE
  • 9 Points
  • Member since 2015
  • Technology Associate|Salesforce Administrator
  • SDR Ventures


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I have a custom covert button that uses the following Apex Class:
public class CustomConvertLead {

    public CustomConvertLead(ApexPages.StandardController controller) {

    }

    public PageReference ConvertL(){
    
        Id idd = ApexPages.CurrentPage().getParameters().get('id');
        Boolean ok = false;
        Id AccId, ConId;
        Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
                   Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
                   AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
                    
                   FROM Lead WHERE Id =:idd LIMIT 1];
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(idd);
        lc.setDoNotCreateOpportunity(true);
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
 
        if (ll.Company__c != null && ll.Contact__c != null){
            lc.setAccountId(ll.Company__c);
            lc.setContactId(ll.Contact__c);
            Database.LeadConvertResult result = Database.convertLead(lc);
        }
        else { 
            ok = true;
            if (ll.Company__c != null) 
                lc.setAccountId(ll.Company__c);
            if (ll.Contact__c != null)
                lc.setContactId(ll.Contact__c);    
            if (ll.Company__c == null){
                List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
                if (cc.size() != 0)
                    lc.setAccountId(cc[0].Id);
            }
            if (ll.Contact__c == null){
                List<Contact> cc =[SELECT Id, AccountId  FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
                if (cc.size() != 0){
                    lc.setAccountId(cc[0].AccountId);
                    lc.setContactId(cc[0].Id);
                }
                
            }
                
            Database.LeadConvertResult result = Database.convertLead(lc);
            AccId = result.getAccountId();
            ConId = result.getContactId();     
        }
        
        Idea_Pitch__c i = new Idea_Pitch__c();
        if (ll.FirstName != null)
            i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
        else 
            i.Name = ll.LastName + ' ' + ll.Company;
        i.Converted_Time_Stamp__c = datetime.now();
        i.Project_Type__c = ll.Reason_Inquiry__c;
        i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
        // what should OwnerId be mapped to
        i.Rating__c = ll.Rating;
        i.Description__c = ll.Description;
        i.Annual_Revenue__c = ll.AnnualRevenue;
        i.EBITDA__c = ll.EBITDA__c;
        i.Capital_Formation_Amount__c = ll.Amount__c;
        i.No_of_Employees__c = ll.NumberOfEmployees;
        i.Status__c = '1. Idea Development';
        i.Lead_Source__c = ll.LeadSource;
        i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
        i.Engagement_Target__c = ll.Engagement_Target__c;
        List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
        if (cms.size() != 0)
            i.Campaign_Conference__c = cms[0].CampaignID;
        if (ok == false){
            i.Company__c = ll.Company__c;
            i.Contact__c = ll.Contact__c;
        }
        else {
            i.Company__c = AccId;
            i.Contact__c = ConId;
        }
        
        INSERT i;
        
        PageReference p = new PageReference('/'+i.Id);
        return p;
    
    }
}
I want to add a few more field updates. I have added the feilds in through the developer console. However you can not add the New Apex Class to an active org. I have the new code built in one of my sandboxes. 

public class CustomConvertLead {

    public CustomConvertLead(ApexPages.StandardController controller) {

    }

    public PageReference ConvertL(){
    
        Id idd = ApexPages.CurrentPage().getParameters().get('id');
        Boolean ok = false;
        Id AccId, ConId;
        Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
                   Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
                   AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
                    
                   FROM Lead WHERE Id =:idd LIMIT 1];
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(idd);
        lc.setDoNotCreateOpportunity(true);
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        
        
        if (ll.Company__c != null && ll.Contact__c != null){
            lc.setAccountId(ll.Company__c);
            lc.setContactId(ll.Contact__c);
            Database.LeadConvertResult result = Database.convertLead(lc);
        }
        else { 
            ok = true;
            if (ll.Company__c != null) 
                lc.setAccountId(ll.Company__c);
            if (ll.Contact__c != null)
                lc.setContactId(ll.Contact__c);    
            if (ll.Company__c == null){
                List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
                if (cc.size() != 0)
                    lc.setAccountId(cc[0].Id);
            }
            if (ll.Contact__c == null){
                List<Contact> cc =[SELECT Id, AccountId  FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
                if (cc.size() != 0){
                    lc.setAccountId(cc[0].AccountId);
                    lc.setContactId(cc[0].Id);
                }
                
            }
                
            Database.LeadConvertResult result = Database.convertLead(lc);
            AccId = result.getAccountId();
            ConId = result.getContactId();     
        }
        
        Idea_Pitch__c i = new Idea_Pitch__c();
        if (ll.FirstName != null)
            i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
        else 
            i.Name = ll.LastName + ' ' + ll.Company;
        i.Converted_Time_Stamp__c = datetime.now();
        i.Project_Type__c = ll.Reason_Inquiry__c;
        i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
        // what should OwnerId be mapped to
        i.Rating__c = ll.Rating;
        i.Description__c = ll.Description;
        i.Annual_Revenue__c = ll.AnnualRevenue;
        i.EBITDA__c = ll.EBITDA__c;
        i.Capital_Formation_Amount__c = ll.Amount__c;
        i.No_of_Employees__c = ll.NumberOfEmployees;
        i.Status__c = '1. Idea Development';
        i.Lead_Source__c = ll.LeadSource;
    i.Lead_Source_New_IdeaO__c = ll.Lead_Source_New_LeadO__c;
        i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
    i.Lead_Source_Description_New_IdeaO__c = ll.Lead_Source_Description_New_LeadO__c;
        i.Engagement_Target__c = ll.Engagement_Target__c;
        List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
        if (cms.size() != 0)
            i.Campaign_Conference__c = cms[0].CampaignID;
        if (ok == false){
            i.Company__c = ll.Company__c;
            i.Contact__c = ll.Contact__c;
        }
        else {
            i.Company__c = AccId;
            i.Contact__c = ConId;
        }
        
        INSERT i;
        
        PageReference p = new PageReference('/'+i.Id);
        return p;
    
    }
}
My question is when I use change set to bring it over, will it just take the place of the orginal code or do I need to do something else?

 
I have a custom covert button that uses the following Apex Class:
public class CustomConvertLead {

    public CustomConvertLead(ApexPages.StandardController controller) {

    }

    public PageReference ConvertL(){
    
        Id idd = ApexPages.CurrentPage().getParameters().get('id');
        Boolean ok = false;
        Id AccId, ConId;
        Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
                   Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
                   AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
                    
                   FROM Lead WHERE Id =:idd LIMIT 1];
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(idd);
        lc.setDoNotCreateOpportunity(true);
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
 
        if (ll.Company__c != null && ll.Contact__c != null){
            lc.setAccountId(ll.Company__c);
            lc.setContactId(ll.Contact__c);
            Database.LeadConvertResult result = Database.convertLead(lc);
        }
        else { 
            ok = true;
            if (ll.Company__c != null) 
                lc.setAccountId(ll.Company__c);
            if (ll.Contact__c != null)
                lc.setContactId(ll.Contact__c);    
            if (ll.Company__c == null){
                List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
                if (cc.size() != 0)
                    lc.setAccountId(cc[0].Id);
            }
            if (ll.Contact__c == null){
                List<Contact> cc =[SELECT Id, AccountId  FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
                if (cc.size() != 0){
                    lc.setAccountId(cc[0].AccountId);
                    lc.setContactId(cc[0].Id);
                }
                
            }
                
            Database.LeadConvertResult result = Database.convertLead(lc);
            AccId = result.getAccountId();
            ConId = result.getContactId();     
        }
        
        Idea_Pitch__c i = new Idea_Pitch__c();
        if (ll.FirstName != null)
            i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
        else 
            i.Name = ll.LastName + ' ' + ll.Company;
        i.Converted_Time_Stamp__c = datetime.now();
        i.Project_Type__c = ll.Reason_Inquiry__c;
        i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
        // what should OwnerId be mapped to
        i.Rating__c = ll.Rating;
        i.Description__c = ll.Description;
        i.Annual_Revenue__c = ll.AnnualRevenue;
        i.EBITDA__c = ll.EBITDA__c;
        i.Capital_Formation_Amount__c = ll.Amount__c;
        i.No_of_Employees__c = ll.NumberOfEmployees;
        i.Status__c = '1. Idea Development';
        i.Lead_Source__c = ll.LeadSource;
        i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
        i.Engagement_Target__c = ll.Engagement_Target__c;
        List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
        if (cms.size() != 0)
            i.Campaign_Conference__c = cms[0].CampaignID;
        if (ok == false){
            i.Company__c = ll.Company__c;
            i.Contact__c = ll.Contact__c;
        }
        else {
            i.Company__c = AccId;
            i.Contact__c = ConId;
        }
        
        INSERT i;
        
        PageReference p = new PageReference('/'+i.Id);
        return p;
    
    }
}
I want to add a few more field updates. I have added the feilds in through the developer console. However you can not add the New Apex Class to an active org. I have the new code built in one of my sandboxes. 

public class CustomConvertLead {

    public CustomConvertLead(ApexPages.StandardController controller) {

    }

    public PageReference ConvertL(){
    
        Id idd = ApexPages.CurrentPage().getParameters().get('id');
        Boolean ok = false;
        Id AccId, ConId;
        Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
                   Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
                   AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
                    
                   FROM Lead WHERE Id =:idd LIMIT 1];
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(idd);
        lc.setDoNotCreateOpportunity(true);
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        
        
        if (ll.Company__c != null && ll.Contact__c != null){
            lc.setAccountId(ll.Company__c);
            lc.setContactId(ll.Contact__c);
            Database.LeadConvertResult result = Database.convertLead(lc);
        }
        else { 
            ok = true;
            if (ll.Company__c != null) 
                lc.setAccountId(ll.Company__c);
            if (ll.Contact__c != null)
                lc.setContactId(ll.Contact__c);    
            if (ll.Company__c == null){
                List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
                if (cc.size() != 0)
                    lc.setAccountId(cc[0].Id);
            }
            if (ll.Contact__c == null){
                List<Contact> cc =[SELECT Id, AccountId  FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
                if (cc.size() != 0){
                    lc.setAccountId(cc[0].AccountId);
                    lc.setContactId(cc[0].Id);
                }
                
            }
                
            Database.LeadConvertResult result = Database.convertLead(lc);
            AccId = result.getAccountId();
            ConId = result.getContactId();     
        }
        
        Idea_Pitch__c i = new Idea_Pitch__c();
        if (ll.FirstName != null)
            i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
        else 
            i.Name = ll.LastName + ' ' + ll.Company;
        i.Converted_Time_Stamp__c = datetime.now();
        i.Project_Type__c = ll.Reason_Inquiry__c;
        i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
        // what should OwnerId be mapped to
        i.Rating__c = ll.Rating;
        i.Description__c = ll.Description;
        i.Annual_Revenue__c = ll.AnnualRevenue;
        i.EBITDA__c = ll.EBITDA__c;
        i.Capital_Formation_Amount__c = ll.Amount__c;
        i.No_of_Employees__c = ll.NumberOfEmployees;
        i.Status__c = '1. Idea Development';
        i.Lead_Source__c = ll.LeadSource;
    i.Lead_Source_New_IdeaO__c = ll.Lead_Source_New_LeadO__c;
        i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
    i.Lead_Source_Description_New_IdeaO__c = ll.Lead_Source_Description_New_LeadO__c;
        i.Engagement_Target__c = ll.Engagement_Target__c;
        List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
        if (cms.size() != 0)
            i.Campaign_Conference__c = cms[0].CampaignID;
        if (ok == false){
            i.Company__c = ll.Company__c;
            i.Contact__c = ll.Contact__c;
        }
        else {
            i.Company__c = AccId;
            i.Contact__c = ConId;
        }
        
        INSERT i;
        
        PageReference p = new PageReference('/'+i.Id);
        return p;
    
    }
}
My question is when I use change set to bring it over, will it just take the place of the orginal code or do I need to do something else?

 
I was a ways through the Admin Trailhead.  After submitting a challenge and error was encountered (sorry I don't remember the error message).  I logged out and then logged back in.  After logging in an error message was displayed stating that the trailhead servers had been overloaded and that I should click the refresh button.  I tried this several time, but to no positive avail.  Finally, I logged out and logged in again.  I was able to log back in, but all of my previous Trailhead progress was gone as if this was a totally new account.
  • September 04, 2015
  • Like
  • 1