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
Sarah PinnsSarah Pinns 

Create Record off Task Creation

Hi! I am looking to trigger a record creation when a task is created.  I would like it to work for if I task is manually created or if it is created through using 'Email to Salesforce'  My code is below but nothing happens when I create task with a status of completed.  Is there something I'm missing?  Appreciate the guidance!
 
trigger createGAActivityonTask on Task (after insert) {
    
    List <RGS_Activity__c> vehToInsert = new List <RGS_Activity__c> ();
    
    
    for (Task o : Trigger.new) {
        
        
        
        if (o.Status == 'Completed') {
        
        RGS_Activity__c v = new RGS_Activity__c (); 
        
        v.Account__c = '001G000001zaW9M';
        v.Contact__c = '00379000004n82q';
        v.Activity__c = 'Email - 1:1'; 
        
        vehToInsert.add(v);
        
        
        }
        
    }
    try {
        insert vehToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

 
Maharajan CMaharajan C
Hi Sarah,

Can you please check any debug got printed inside catch... or ... remove the try catch from you trigger then execute to see if there is any error.

Also please check whether you are passing all the mandatory data for RGS_Activity__c  record creation... Avoid the hardcoded record id's...

If you got any error please post the error message here.

Thanks,
Maharajan.C