-4

Just want to know what am I missing here.

trigger updateLastCallDate on Task (after insert, after update, after delete) {

    Set<Id> con_set = new Set<Id>();

    List<Contact> con_list = new List<Contact>();

    for(Task T: Trigger.new()){
        if(String.valueof(T.WhatId).startsWith('001') &&
            T.Status=='Completed' && T.Subject=='Call' ) {
            con_set.add(T.WhatId);
        }
     }

     for (AggregateResult aggregateResult: [SELECT max(createdDate)MaxCDate, WhatId
        FROM Task WHERE WhatID IN: con_set AND Status ='Completed'
        AND Subject ='Call' Group By WhatId]) {
        con_list.add(new Contact(Id=(id)aggregateResult.get('WhatId'),Last_Call__c=date.valueof(aggregateResult.get('MaxCDate'))));
     }

     try {
         if(con_list !=null && con_list.size()>0) {
             update con_list;
         }
     } catch(Exception e) {
         system.debug('Exception ***'+e.getMessage());
     }
  }
2
  • Can you provide more information? Are you receiving an error? If so, can you include it in your question?
    – Nick C
    Dec 18, 2015 at 2:44
  • one mistake i noticed you are adding AccountId in con_set this set and below assigning AccountId to contact Contact(Id=(id)aggregateResult.get('WhatId').... Except this code look good to me. pls specify line no where you are getting eror
    – Ratan Paul
    Dec 18, 2015 at 2:47

1 Answer 1

7

The compile error is because you have this:

for(Task T: Trigger.new()){

so the compiler thinks .new() is a method on a variable named Trigger, when it's actually a system context variable. It should be:

for (Task t : trigger.new) {
5
  • 2
    Nice one. It's only now that you've posted this that the question makes sense.
    – Nick C
    Dec 18, 2015 at 3:25
  • ohh yes this is the mistake.
    – Ratan Paul
    Dec 18, 2015 at 4:40
  • Thansk for the comments guys but... It's giving me an error... Trigger name exists on different SObject type: Contact If I change Task to contact then I have to change all "Task" then it gives me an error that WHATID doesnt exist. Isnt the sObject has to be on contact?
    – Ninja King
    Dec 18, 2015 at 17:35
  • That error means that you already have a trigger on Contact named the same thing...rename this one to resolve it. If this answer answered your question and if you have a different question, please create a new post :) Dec 18, 2015 at 17:37
  • I actually dont. :( I renamed a couple of times and the same error
    – Ninja King
    Dec 18, 2015 at 17:48

You must log in to answer this question.

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