function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul Sangwan7341Rahul Sangwan7341 

I am using bcc to salesforce, and i have to create a new task when mail comes with specified subject

using bcc to salesforce, and i have to create a new task when mail comes with specified subject. I had written a trigger on Task. In case when i am sending bcc to lead its working fine but in case of Contact whoId is always coming as null, i tried with both after insert and after update.

This is trigger I had written:
trigger bccTrigger on Task (after insert, after update) {

    //TaskTriggerHelper.createNewTask(Trigger.new);
    List<Task> tnew=trigger.new;
    List<Task> tc=[Select Id,Subject,Dummy_Number__c,WhoId from Task where id in:tnew];
    List<Task> tk=new List<Task>();
    If(Trigger.isInsert){
        if(Trigger.isAfter){
        for(Task t:tc){
        system.debug('............Insert.......'+t.WhoId+'.....'+t.Id);
            if((t.Subject).equals('Email: GroupBy / Searchandiser Introduction')){
                t.Dummy_Number__c=t.Dummy_Number__c+1;
                }
            }
            update tc;
        }
    }

    if(Trigger.isUpdate){
        if(Trigger.isAfter){
            for(Task t:tc){
            system.debug('............Update.......'+t.WhoId+'.....'+t.Id);
            if((t.Subject).equals('Email: GroupBy / Searchandiser Introduction')){
                Task tadd=new Task();
                tadd.Subject='Test1';
                tadd.WhoId=t.WhoId;
                tk.add(tadd);
                }
            }
            insert tk;
        }
    }

}
SonamSonam (Salesforce Developers) 
If you are using BCC(email to Salesforce) address to add emails to Salesforce, Contacts remain NULL in case there are more than 1 contact with the same email address, is this the thing happening with your tasks as well?
 
Rahul Sangwan7341Rahul Sangwan7341
yeah i checked that thing.....the email id is unique in Contact, and i also checked that this email id is also not present in Account also.
SonamSonam (Salesforce Developers) 
Let me try this trigger on my test ORG? 

Would help if you could explain the following statement - "I also checked that this email id is also not present in Account also.

Are these contacts personal contacts without account associations?
Rahul Sangwan7341Rahul Sangwan7341
let me check that
Rahul Sangwan7341Rahul Sangwan7341
No these accounts are attached with Accounts. I don't know i tried in another instance its working fine there.
Thomas Graves 1Thomas Graves 1
Did you all ever figure this out? I'm running into this wall currently where the whoId is null. I really need a way to set it and process my trigger.

--Thomas