I've authored this trigger but around line 8, where the if(string.valueof) statement begins, I seem to be stuck in that I get the message "Initial term of field expression must be a concrete object."

I am authoring a trigger that creates a task each time an email is sent and assigns a WhoId based on the email address of the recipient. Are there any steps I should take?

Hope it helps,

trigger EmailToTask on EmailMessage (after insert) {
    list<Task> lstTask= new list<Task>();
    map<String,Id> mapEmail = new map<String,Id>();
    map<String,Id> mapWorkEmail = new map<String,Id>();
    map<String,Id> mapHomeEmail = new map<String,Id>(); 
    for(Contact con: [SELECT Id,Email,npe01__WorkEmail__c,npe01__HomeEmail__c FROM Contact]){

    for (EmailMessage e : Trigger.new) {
       if (e.RelatedToId != NULL 
       && (mapEmail <> NULL && !mapEmail.isEmpty()
           || mapWorkEmail <> NULL && !mapWorkEmail.isEmpty()
           || mapHomeEmail <> NULL && !mapHomeEmail.isEmpty())
           ) {
           Task t =  new Task();
           t.ActivityDate  = date.today();
           t.Description   = e.TextBody;
           t.Move_Type__c  = 'Personal Note/Email from Donor';
           t.Priority      = 'Normal';
           t.Status        = 'Completed';
           t.Subject       = e.Subject;
           t.WhatId        = e.RelatedToId;
                t.WhoId =mapEmail.get(e.ToAddress);
           else if(mapWorkEmail.containsKey(e.ToAddress )){
                t.WhoId =mapWorkEmail.get(e.ToAddress);
           else if(mapHomeEmail.containsKey(e.ToAddress )){
                t.WhoId =mapHomeEmail.get(e.ToAddress);
    if(lstTask <> NULL && !lstTask.isEmpty()){
        insert lstTask;
  • 1
    I think you are trying to call String.isNotBlank(con.Email) and the same on these other fields? – Adrian Larson Jul 5 '17 at 15:05
  • Correct, but specifically with three different types of email fields that are being queries (one is a general catch all email address, another is work and personal). We're using the Nonprofit Success Pack model which provides these emails fields to us, and going based on whether there is a match in the email to address to one of these three fields in a respective contact record, which populates the WhoId associated with the respective email addresses. – Medhanie Habte Jul 5 '17 at 15:14

It is easy enough to reproduce this error message with a similar anonymous script:


Contact record = [SELECT Email FROM Contact LIMIT 1];
Boolean b = String.valueOf(record.Email).isNotBlank;

You can't check for blank strings like that; isNotBlank is a method which you must call, and it is static as well.


Contact record = [SELECT Email FROM Contact LIMIT 1];
Boolean b = String.isNotBlank(record.Email);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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