Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 =;
    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;
share|improve this question
up vote 6 down vote accepted

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);
share|improve this answer
I thought I had tried that, but apparently not. Worked. – Merry Apr 18 '14 at 19:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.