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
Mansi Mehta 65Mansi Mehta 65 

Relative List 'Notes' to be updated using Apex when a custom field limit exceeds.

I want to update the Salesforce notes on Related List when a custom field on Account object length exceeds a certain limit, for eg:3000.

how to achieve it using Apex class.

ShirishaShirisha (Salesforce Developers) 
Hi Mansi,

Greetings!

This can be achieved by the Apex trigger and you need to make sure which should be updated on the Notes Object.Please check the sample code in the below thread.

https://salesforce.stackexchange.com/questions/102643/update-a-text-field-from-custom-object-to-notes-related-list

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
ravi soniravi soni
Hi Mansi,
try this following Apex Trigger.
trigger UpdateNote on Account (after Update) {
    if(trigger.isAfter && trigger.isUpdate){
    
        set<Id> AccIdSet = new set<Id>();
    list<Note> lstNote = new list<Note>();
        Map<Id,String> AccDescriptionMap = new Map<Id,String>();
        
        for(Account Acc : trigger.new){
              AccIdSet.add(acc.Id);
          AccDescriptionMap.put(acc.Id,acc.Description);
        }
        
        for(Note oNote : [SELECT Id,Title,Body,ParentId From Note WHERE ParentId IN : AccIdSet]){
            if(AccDescriptionMap.containsKey(oNote.ParentId)){
               
            if(AccDescriptionMap.get(oNote.ParentId)!= null && AccDescriptionMap.get(oNote.ParentId).length() > 3000){
               
            oNote.Body = AccDescriptionMap.get(oNote.ParentId); 
            lstNote.add(oNote);
          
                
            }    
            }
            
            }

                
                
        if(lstNote.size() > 0){
            update lstNote;
        }
        
        
    }
   
}
let me know if it's helps you and close your query to marking it as best.