function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amanda ReamAmanda 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;
        }
    }
}

 
Best Answer chosen by Amanda Ream
James LoghryJames Loghry
Replace '=' with ':' and that'll fix that specific compile error.

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

James LoghryJames Loghry
Replace '=' with ':' and that'll fix that specific compile error.

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?
This was selected as the best answer
Shephali SwarnkarShephali Swarnkar
Hi Amanda Ream,
   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
Amanda ReamAmanda Ream
James - Long Text Area Fields are not supported in text formula fields :(

Thank you both for your help! 

 
James LoghryJames Loghry
Ah yes.  Bummer.