You need to sign in to do that
Don't have an account?
Kyle Armstrong
Compile Error: Initial term of field expression must be a concrete SObject: List<String>
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 ); }
Please remove <i><b> tags from line no. 33 and then try to save.
@sumit singh 37 - I tried replacing line 33 of code with what you recommended, but I then get an error at line 33 column 41.
You will have to write email.subject instead of writing emailBody.subject at both line 33 and 36 since subject is a property of email.
That specific error was taken care of, but now I receive error: Compile Error: Condition expression must be of type Boolean at line 33 column 25.
Thank you,
Kyle
use if(emailBody[0].subject == 'Life Insurance Lead') give the appropriate index number
Please use == instead of single = in the condition.
emailBody is a Array of String. So you cannot use emailBody.subject directly. You need to specify index in array. Try below code:
Thanks,
Himanshu
Use below mentioned code snippet as a replacement from line no 33 to 38, it may solve your problem: