• Kyle Armstrong
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I'm working with incoming leads from vendors via email.  I'm trying to have the lead associated with the correct campaign name, but am getting the error "Compile Error: Initial term of field expression must be a concrete SObject: List<String> at line 33 column 28."  I have made the line in question bold and italics.
                       
global class CreateLeadFromEmail implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult HandleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope env) {
        
        // Create an InboundEmailResult object for returning the result of the  
        // Apex Email Service 
        String campaignName;
       
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String convertToPlainText= '';
        // Add the email plain text into the local variable  
        convertToPlainText = email.plainTextBody;
        System.debug('Email Content: ' + convertToPlainText);   
        //check if the incoming email Lead has an email address
        if(email.plainTextBody != ''){
            String[] emailBody = email.plainTextBody.split('\n', 0);
            System.Debug(emailBody);
            String LeadEmail = emailBody[6].substringAfter(': ').trim();            
            if(String.isNotBlank(LeadEmail)){
                Integer leadCount = [select count() from Lead where Email =: LeadEmail];
                List<Lead> leadList = [SELECT Id,status FROM Lead WHERE Email = : LeadEmail];
                System.debug('Lead count from the existing Lead with the requested emailId -'+ leadCount);
                //if (leadList.size() == 0 || leadList.size() > 1) {
                    try{
                        //Create new Lead as it does not exist
                        Lead createNewLead = new Lead();
                        //Set the Lead object values from the email body
                        createNewLead = CreateOrUpdateLead(createNewLead, emailBody);
                        System.debug('Before Lead insert');
                        insert createNewLead;    
                        System.debug('After Lead insert');
                        system.debug('Inserted Lead Id = '+ createNewLead.Id);
                        //Add the Lead to the correct campaign
                        if(emailBody.subject = 'Life Insurance Lead'){
                            campaignName = 'The Lead Guys';         
                        }
                        else if (emailBody.subject == 'New Webform Lead Notification'){
                            campaignName = 'Get Seen Media';
                        }
                            
                        Campaign campaignId = [Select id from Campaign where name =: campaignName]; 
                        CampaignMember leadCampaignMember = new CampaignMember(campaignid = campaignId.id, leadid = createNewLead.Id);
                        insert leadCampaignMember;
                        System.debug('New Lead record: ' + createNewLead );   
                    }
I'm working with incoming leads from vendors via email.  I'm trying to have the lead associated with the correct campaign name, but am getting the error "Compile Error: Initial term of field expression must be a concrete SObject: List<String> at line 33 column 28."  I have made the line in question bold and italics.
                       
global class CreateLeadFromEmail implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult HandleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope env) {
        
        // Create an InboundEmailResult object for returning the result of the  
        // Apex Email Service 
        String campaignName;
       
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String convertToPlainText= '';
        // Add the email plain text into the local variable  
        convertToPlainText = email.plainTextBody;
        System.debug('Email Content: ' + convertToPlainText);   
        //check if the incoming email Lead has an email address
        if(email.plainTextBody != ''){
            String[] emailBody = email.plainTextBody.split('\n', 0);
            System.Debug(emailBody);
            String LeadEmail = emailBody[6].substringAfter(': ').trim();            
            if(String.isNotBlank(LeadEmail)){
                Integer leadCount = [select count() from Lead where Email =: LeadEmail];
                List<Lead> leadList = [SELECT Id,status FROM Lead WHERE Email = : LeadEmail];
                System.debug('Lead count from the existing Lead with the requested emailId -'+ leadCount);
                //if (leadList.size() == 0 || leadList.size() > 1) {
                    try{
                        //Create new Lead as it does not exist
                        Lead createNewLead = new Lead();
                        //Set the Lead object values from the email body
                        createNewLead = CreateOrUpdateLead(createNewLead, emailBody);
                        System.debug('Before Lead insert');
                        insert createNewLead;    
                        System.debug('After Lead insert');
                        system.debug('Inserted Lead Id = '+ createNewLead.Id);
                        //Add the Lead to the correct campaign
                        if(emailBody.subject = 'Life Insurance Lead'){
                            campaignName = 'The Lead Guys';         
                        }
                        else if (emailBody.subject == 'New Webform Lead Notification'){
                            campaignName = 'Get Seen Media';
                        }
                            
                        Campaign campaignId = [Select id from Campaign where name =: campaignName]; 
                        CampaignMember leadCampaignMember = new CampaignMember(campaignid = campaignId.id, leadid = createNewLead.Id);
                        insert leadCampaignMember;
                        System.debug('New Lead record: ' + createNewLead );   
                    }