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;
}
}
String.isNotBlank(con.Email)
and the same on these other fields?