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
TerminusbotTerminusbot 

Lightning Experience: New Notes - Apex Trigger Issue

Hello,

I just created an Apex Trigger (with the help of the forum) on the Note object. The trigger works great when a new note is created from the Old-Note section but does not work when entering a note from the new lightning experience. Are the new notes being writting in a different object? Any guidance would be fantastic. 
trigger UpdateOppLastNote on Note (after insert, after update) {

List<Opportunity> oppLstToUpdate=new List<Opportunity>();
    if(Trigger.isInsert){
        for(Note nt : Trigger.new){
            if(String.valueOf(nt.parentId).startsWith('006')){
                Opportunity opp=new Opportunity(Id=nt.parentId,Latest_Note__c=nt.Title + ': ' + nt.Body); 
                oppLstToUpdate.add(opp);
            }   
        }
    }if(Trigger.isUpdate){
        for(Note nt : Trigger.new){
            if(String.valueOf(nt.parentId).startsWith('006')){
                if(nt.Body != Trigger.oldMap.get(nt.Id).Body){
                   Opportunity opp=new Opportunity(Id=nt.parentId,Latest_Note__c=nt.Title + ': ' + nt.Body); 
                    oppLstToUpdate.add(opp);
                }
            }
        }
    }
    if(!oppLstToUpdate.isEmpty()){
        try{
            update oppLstToUpdate;
        }catch(DmlException de ){
            System.debug(de);
        }
    }


}

 
Best Answer chosen by Terminusbot
JustAGirlyGeekJustAGirlyGeek
Yes, I believe the new Notes is using a different object called ContentNote:

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentnote.htm