You need to sign in to do that
Don't have an account?
QD93
Apex Trigger: Cross Object Field Update on Task WhatID from related Contact(WhoId)
New to Apex...
Whenever a Task is created, I'd like to relate the Task's WhatID to the related Contact's (whoid) lookup field (custom field) TriggerTest__c.
I have been receivin this error message : Error: Compile Error: Cannot save a trigger during a parse and save class call at line -1 column -1
Whenever a Task is created, I'd like to relate the Task's WhatID to the related Contact's (whoid) lookup field (custom field) TriggerTest__c.
I have been receivin this error message : Error: Compile Error: Cannot save a trigger during a parse and save class call at line -1 column -1
trigger TaskRelatedToContact on Task (after insert,after update) { Set<Id> ContactIds = new Set<Id>(); for(Task t : trigger.new) {String wId = t.WhoId; if(wId!=null && wId.startsWith('003') && !ContactIds.contains(t.WhoId)) { ContactIds.add(t.WhoId); } } List<Contact> taskContacts = [Select Id, TriggerTest__c from Contact where Id in :ContactIds]; Map<Id, Contact> ContactMap = new Map<Id, Contact>(); for(CONTACT c : taskContacts) { ContactMap.put(c.Id,c); } for(Task t : trigger.new){ String wId = t.WhoId; if(wId!=null && wId.startswith('003')){CONTACT thisContact = ContactMap.get(t.WhoId); if(thisContact!=null){t.WhatId = thiscontact.TriggerTest__c;} } } }
Try this
All Answers
if problem get solved then please marked this as a best answer
Unfortunately, still receiving the same error message. Error: Compile Error: Cannot save a trigger during a parse and save class call at line -1 column -1
in quick find box go to -> apex trigger then edit and save this code which I provided u
Note: the TriggerTest__c is a lookup field from the Contact record to a custom object. I am receiving this error:
Is it because I can't use After Insert and After Update on the same 'Task record' that the trigger was on to update a lookup field (whatid)?
Chnage the event do it in before for both the events update and insert?
Try this
I m so happy that it worked, Thanks for marking my answer as a best answer :)
Thanks
Saket Sharma
sharmasaket703@gmail.com