You need to sign in to do that
Don't have an account?

update a custom field with last event createddate
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
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
In that case you should try this:
Let me know if worked.
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
All Answers
I am afraid you cannot update a CreatedDate field as it is read-only. Moreover, you should bulkify your triggers instead of explicitly access only the first record in the Trigger.new collection. Find out more about here:
https://developer.salesforce.com/page/Apex_Code_Best_Practices (https://developer.salesforce.com/page/Apex_Code_Best_Practices" target="_blank)
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Hello,
So are you trying to get the CreatedDate of a Task an set it in the Score__c of Sample__c. Did I get it right?
In that case you should try this:
Let me know if worked.
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.