0

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]){
        if(string.valueOf(con.Email).isNotBlank)
            mapEmail.put(con.Email,con.Id);
        if(string.valueOf(con.npe01__WorkEmail__c).isNotBlank)
            mapWorkEmail.put(con.npe01__WorkEmail__c,con.Id);
        if(string.valueOf(con.npe01__HomeEmail__c).isNotBlank)
            mapHomeEmail.put(con.npe01__HomeEmail__c,con.Id);
    }

    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;
           if(mapEmail.containsKey(e.ToAddress)){
                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);
           }
           lstTask.add(t);
        }
    }
    if(lstTask <> NULL && !lstTask.isEmpty()){
        insert lstTask;
    }
}
2
  • 1
    I think you are trying to call String.isNotBlank(con.Email) and the same on these other fields?
    – Adrian Larson
    Commented Jul 5, 2017 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. Commented Jul 5, 2017 at 15:14

1 Answer 1

4

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

Incorrect

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.

Correct

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .