Skip to main content
Arash Teimoupoor a posé une question dans #Apex
Hi Everyone, I'm trying to update a custom field on my sample object with the creation date of any task that is created. I receive the following error when I try to save the trigger:

Error: Compile Error: Initial term of field expression must be a concrete SObject: List<OpenActivity> at line 8 column 2

below is my trigger:

trigger UpdatePresDate on Task(after insert, after delete){

 Set<ID> tWhatIDs = new Set<ID>();

Task t= Trigger.new[0];

List<Sample__c> acclist = new List<Sample__C>();

    List<OpenActivity> openlist = new List<OpenActivity>();

    

 acclist = [Select Score__C, (Select Id, CreatedDate From OpenActivities where isTask =: true ) From Sample__C where Id IN: tWhatIDs];

 openlist.CreatedDate = acclist.Score__C;

update acclist;

}

what should I change in my trigger? Thanks in advance

 
7 réponses
  1. 3 févr. 2015, 23:47
    Hello,

    In that case you should try this:

     

    trigger UpdatePresDate on Task(after insert){

    Map<Id, Datetime> sampleDates = new Map<Id, Datetime>();

    for (Task tsk : Trigger.new) {

    if (tsk.WhatId.getSObjectType() == Sample__c.sObjectType)

    sampleDates.put(tsk.WhatId, tsk.CreatedDate);

    }

    // Mass updates records avoiding heap limit.

    // https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm

    for (List<Sample__c> samples : [SELECT Id, Score__c FROM Sample__c WHERE Id =: sampleDates.keySet()]) {

    for (Sample__c sample : samples) {

    sample.Score__c = sampleDates.get(sample.Id);

    }

    Database.update(samples);

    }

    }

    Let me know if worked.

    Regards.

    Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
0/9000