4

I need to have a trigger that updates a date on the contact based on whether a task was created with two specific dispositions (Call_Disposition__c is a custom field on the Activity). Since the field that I need to filter by is on the activity and not on the task it appears that I cannot do this - just checking to see if I am correct and this is not going to be possible. I get the message - No Access to Entity: Activity.

trigger LastQteamUpdate on Task (after insert, after update) {

    // set up lists you will need
    datetime myDate = datetime.now();
    List<Contact> consToUpdate = new List<Contact>();
    Map<Id, Task> taskMap = new Map<Id, Task>();


    // go through the list of tasks that were inserted
    for (Task t: Trigger.New){
        // if they are related to a contact, add the contact id (whoID) and their values to a map
        if (t.WhatId  != null && (Activity.Call_Disposition__c == 'Contact - Call'|Activity.Call_Disposition__c == 'Contact - Email' ) ){
            taskMap.put(t.WhatId, t);
        }
    }

    // if the map isnt empty  
    // *** saying !taskMap.isEmpty() costs much less than using taskMap.size()>0  ***
    system.debug('taskMap = '+taskMap);
       if (taskMap.size() > 0)
    {
        // get all of the contacts related to the tasks
       consToUpdate = [SELECT Id, Last_SDR_Update__c, Last_person_to_edit_task__c
                        FROM Contact 
                        WHERE Id IN: taskMap.keySet()];
        // go through the list for each contact
        for (Contact c: consToUpdate){
            // set the SDR update field to the date
            c.Last_SDR_Update__c = myDate;
            c.Last_person_to_edit_task__c = userinfo.getName();
                    }

        // if the list of cons isnt empty, update them
        system.debug('consToUpdate = '+consToUpdate);
        if (consToUpdate.size() > 0)
        {
            update consToUpdate;
        }
    }
}
0

1 Answer 1

8

Activity is the base shape of Task and Event, custom fields on the activity object are inherited by Task and Event.

You should be able to just do:

  for (Task t: Trigger.New){
        // if they are related to a contact, add the contact id (whoID) and their values to a map
        if (t.WhatId  != null && (t.Call_Disposition__c == 'Contact - Call'|t.Call_Disposition__c == 'Contact - Email' ) ){
            taskMap.put(t.WhatId, t);
        }
    }
1
  • I thought I had tried that, but apparently not. Worked. Commented Apr 18, 2014 at 19:46

You must log in to answer this question.

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