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
Harsh Singh 7Harsh Singh 7 

Rich Text Area on Event Object

 if(Trigger.isafter && Trigger.isupdate){
            for(Event objEve : Trigger.new){
                if(objEve.Description_RTA__c == Null ){
                break;
                }
                if(objEve.Description_RTA__c != Trigger.oldMap.get(objEve.Id).Description_RTA__c ){
                if(objEve.Description_RTA__c.Contains('<img') && objEve.Description_RTA__c != Null ){                    
                Attachment newattachment = new Attachment();   
                newattachment.Body = Blob.valueOf(objEve.Description_RTA__c);
                newattachment.Name = String.valueOf('image.jpg');
                newattachment.ParentId =objEve.Id; 
                buffer_Attac.add(newattachment);       
               }
                else if(objEve.Description_RTA__c != Null){    
                        Attachment newattachment = new Attachment();   
                        newattachment.Body = Blob.valueOf(objEve.Description_RTA__c);
                        newattachment.Name = String.valueOf('test.txt');
                        newattachment.ParentId =objEve.Id; 
                        buffer_Attac.add(newattachment);   
                       }
                 }       
            }     
     }
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Issue-
On Event object their is no rich text area, so user wanted to have the rich text area, i have created the visual force page and add in the page layout of event.
I have also add the trigger on event object so when user make any changes in that visual force page than it will save in the attachment as a file text or a image jpg .
The issue is whenever user make any changes in the rich text area. than every time it is creating the new file and attached in the section, but this need to be stop and only one time it should added and next time they need to update than attachment.
Hint-
1. Either my removing the file
2. Deleting the file
 
Steven NsubugaSteven Nsubuga
Either get rid of '&& Trigger.isupdate' or update the code to handle the possible update of the attachment.