You need to sign in to do that
Don't have an account?
Amanda Ream
Trigger to update custom field in Events
I am trying to write a trigger on the Events object that copies from the standard description field (32,000 char) to a custom field (255 char). I am doing this because SF does not allow fields with more than 255 characters to be pulled into reports.I first tried to do this with a workflow but there was an issue that system wasn't recognizing the changes on edit (I filed a case with SF). They provided a workaround solution but I thought it would be easier to just write a trigger. I have the trigger written but I am getting the error "expecting semi-colon, found ')'" on the for line. Does anyone know why this is occuring?
trigger EventUpdate on Event (before insert, before update) {
for (Event a = Trigger.new){
List<Event,Id> Event = new List<Id>([SELECT Id from Event where Id IN : trigger.newList.keySet() ]);
if (event.Description != null){
a.customfield__c = event.Description;
} else {
a.customfield_copy__c = null;
}
}
}
trigger EventUpdate on Event (before insert, before update) {
for (Event a = Trigger.new){
List<Event,Id> Event = new List<Id>([SELECT Id from Event where Id IN : trigger.newList.keySet() ]);
if (event.Description != null){
a.customfield__c = event.Description;
} else {
a.customfield_copy__c = null;
}
}
}
Also, did you try writing a simple formula instead, that uses LEFT(Description,255) or something similar, and seeing if that works with your report instead of writing a trigger?
All Answers
Also, did you try writing a simple formula instead, that uses LEFT(Description,255) or something similar, and seeing if that works with your report instead of writing a trigger?
Try Below code.
trigger EventUpdate on Event (before insert, before update) {
for (Event a = Trigger.new){
if (a.Description != null)
a.customfield__c = a.Description.left(255);
}
}
Thanks
Shephali
Thank you both for your help!