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
Bogdan PascuBogdan Pascu 

trigger to copy the value from one filed to another one

Hello I would need some help in building a trigger on the Event object. I need to copy the value from a custom field "ClientFeedback__c" to a standard one on the same object: "Description". I am missing this part from the trigger. 
 
trigger showingWorkflowTrigger on Event (after insert, after update) {

        List<Event> events = Trigger.new;
        Map<Id, Event> oldEvents = null;
        if (Trigger.isUpdate) {
            oldEvents = Trigger.oldMap;
        }
        
        
        for (Event event : events) {
            
            RecordType rt = [Select Name FROM RecordType where Id=:event.RecordTypeId];
            
            if (rt.Name == 'Showing' && event.WhoId != null) {


}
                
                if (Trigger.isUpdate) {
                     Event oldEvent = oldEvents.get(event.Id);

 
GauravendraGauravendra
Hi Bogdan,
You can try something like this:
trigger eventTrigger on Event (before insert, before update) {

    for(Event ev : Trigger.New) {
    	ev.Description = ev.Feedback__c;    
    }   
}
Hope this helps!
Bogdan PascuBogdan Pascu
hello I forgot to mention that the custom filed Feedback__c exist on the standard salesforce object "Activity". Do you know how to referance to another object? 
GauravendraGauravendra
Yeah..it will work fine. Had you tried that code in before trigger?
You cannot create custom fields on Event object, it will go under activity only.
Bogdan PascuBogdan Pascu
hello yes I have tried with the code but it is not working as I get th error that my custom filed does not exist Feedback__c

I also need the trigger to work after insert, after update and not before
GauravendraGauravendra
You need to use "ClientFeedback__c" in your case. I just given "Feedback__c" as example.
ev.Description = ev.ClientFeedback__c